Jump to content

[SOLVED] How to use HTML in Catagory Descriptions


Recommended Posts

I don't think you can use HTML in category description.
it will be stripped off when you click save button.

you have try to change it in database directly, but this has risk of lost when you update it on back office next time.

Please do not link me to the french explanation of this that exists on the forum

you can try to use Google translation, it is pretty good enough. ;-)
Link to comment
Share on other sites

create a file called Category.php and put it in the /override/classes folder, and add this content to it. This works for v1.4.0.17, and may need to be revised slightly for future versions, i have not tried it yet on v1.4.1 or greater.

<?php

class Category extends CategoryCore
{
   public function getTranslationsFieldsChild() {
       self::validateFieldsLang();

       $fieldsArray = array('name', 'link_rewrite', 'meta_title', 'meta_keywords', 'meta_description');
       $fields = array();
       $languages = Language::getLanguages();
       $defaultLanguage = Configuration::get('PS_LANG_DEFAULT');
       foreach ($languages as $language)
       {
           $fields[$language['id_lang']]['id_lang'] = $language['id_lang'];
           $fields[$language['id_lang']][$this->identifier] = intval($this->id);
           $fields[$language['id_lang']]['description'] = (isset($this->description[$language['id_lang']])) ? Tools::htmlentitiesDecodeUTF8(pSQL($this->description[$language['id_lang']], true)) : '';
           foreach ($fieldsArray as $field)
           {
               if (!Validate::isTableOrIdentifier($field))
                   die(Tools::displayError());

               /* Check fields validity */
               if (isset($this->{$field}[$language['id_lang']]) AND !empty($this->{$field}[$language['id_lang']]))
                   $fields[$language['id_lang']][$field] = pSQL($this->{$field}[$language['id_lang']]);
               elseif (in_array($field, $this->fieldsRequiredLang))
                   $fields[$language['id_lang']][$field] = pSQL($this->{$field}[$defaultLanguage]);
               else
                   $fields[$language['id_lang']][$field] = '';
           }
       }
       return $fields;
   } 
}

  • Like 3
Link to comment
Share on other sites

Thanks for the info... however I am using version PrestaShop™ 1.4.3.

My apologies for not being more specific...

I tried creating the file and putting it in place and it did not work...

Any other ideas?

Thanks,
Joe Cap

Link to comment
Share on other sites

bellini13 thanks so much for this. I have it working in v 1.4.3.

Further to this if you want to convert tags in the category list in the admin area edit classes/AdminTab.php and add in
Tools::htmlentitiesUTF8 to the value being printed.

~ line 1492
change

$echo = ($key == 'price' ? round($tr[$key], 2) : isset($params['maxlength']) ? Tools::substr($tr[$key], 0, $params['maxlength']).'...' : $tr[$key]);

to

$echo = ($key == 'price' ? round($tr[$key], 2) : isset($params['maxlength']) ? Tools::substr(Tools::htmlentitiesUTF8($tr[$key]), 0, $params['maxlength']).'...' : Tools::htmlentitiesUTF8($tr[$key]));

Note the whole function should actually go in the override folder.

I will update my blog post to reflect all this asap. Also to show the html editor.

Link to comment
Share on other sites

  • 1 month later...

Thanks Jellygnite - the info you posted in your blog works like a charm on version 1.4. Took all of 5 minutes to put into place! Only thing better would be to pull in the ckeditor for category descriptions - like what is used for the Short and Long product descriptions. Why doesn't prestashop use that feature for all descriptions?

Link to comment
Share on other sites

  • 4 weeks later...
  • 2 weeks later...

Hi polaije, i found that BO problem was because i copy the code from the "copy code" button. Open it as "view simple" and try again.

 

I finally get it working! i was overwritting category-branch-tree.tpl intead of putting the modified file on theme folder.

Link to comment
Share on other sites

  • 4 months later...

Thank you very much for this. I'm having only one problem. Added in TinyMCE, I'm using Prestashop V4.7. When I adjust a font size of a word, all words in my paragraph adjust to the same size. When I apply bold to a word all words go bold. Is this just me?

Link to comment
Share on other sites

  • 1 month later...

create a file called Category.php and put it in the /override/classes folder, and add this content to it. This works for v1.4.0.17, and may need to be revised slightly for future versions, i have not tried it yet on v1.4.1 or greater.

 

<?php

class Category extends CategoryCore
{
public function getTranslationsFieldsChild() {
	self::validateFieldsLang();

	$fieldsArray = array('name', 'link_rewrite', 'meta_title', 'meta_keywords', 'meta_description');
	$fields = array();
	$languages = Language::getLanguages();
	$defaultLanguage = Configuration::get('PS_LANG_DEFAULT');
	foreach ($languages as $language)
	{
		$fields[$language['id_lang']]['id_lang'] = $language['id_lang'];
		$fields[$language['id_lang']][$this->identifier] = intval($this->id);
		$fields[$language['id_lang']]['description'] = (isset($this->description[$language['id_lang']])) ? Tools::htmlentitiesDecodeUTF8(pSQL($this->description[$language['id_lang']], true)) : '';
		foreach ($fieldsArray as $field)
		{
			if (!Validate::isTableOrIdentifier($field))
				die(Tools::displayError());

			/* Check fields validity */
			if (isset($this->{$field}[$language['id_lang']]) AND !empty($this->{$field}[$language['id_lang']]))
				$fields[$language['id_lang']][$field] = pSQL($this->{$field}[$language['id_lang']]);
			elseif (in_array($field, $this->fieldsRequiredLang))
				$fields[$language['id_lang']][$field] = pSQL($this->{$field}[$defaultLanguage]);
			else
				$fields[$language['id_lang']][$field] = '';
		}
	}
	return $fields;
}
}

 

 

Very nice and helpful.

Link to comment
Share on other sites

  • 4 weeks later...

hi, I've PRESTASHOP 1.4.7.0 and when I've inserted HTML tags PS convert the html tags in HTML Special chars in the frontend. For example If I insert the tag

<p>

it is converted to

<p>

 

Something is wrong in my code.... Anybody can help me?

Link to comment
Share on other sites

  • 2 months later...

create a file called Category.php and put it in the /override/classes folder, and add this content to it. This works for v1.4.0.17, and may need to be revised slightly for future versions, i have not tried it yet on v1.4.1 or greater.

 

<?php

class Category extends CategoryCore
{
public function getTranslationsFieldsChild() {
	self::validateFieldsLang();

	$fieldsArray = array('name', 'link_rewrite', 'meta_title', 'meta_keywords', 'meta_description');
	$fields = array();
	$languages = Language::getLanguages();
	$defaultLanguage = Configuration::get('PS_LANG_DEFAULT');
	foreach ($languages as $language)
	{
		$fields[$language['id_lang']]['id_lang'] = $language['id_lang'];
		$fields[$language['id_lang']][$this->identifier] = intval($this->id);
		$fields[$language['id_lang']]['description'] = (isset($this->description[$language['id_lang']])) ? Tools::htmlentitiesDecodeUTF8(pSQL($this->description[$language['id_lang']], true)) : '';
		foreach ($fieldsArray as $field)
		{
			if (!Validate::isTableOrIdentifier($field))
				die(Tools::displayError());

			/* Check fields validity */
			if (isset($this->{$field}[$language['id_lang']]) AND !empty($this->{$field}[$language['id_lang']]))
				$fields[$language['id_lang']][$field] = pSQL($this->{$field}[$language['id_lang']]);
			elseif (in_array($field, $this->fieldsRequiredLang))
				$fields[$language['id_lang']][$field] = pSQL($this->{$field}[$defaultLanguage]);
			else
				$fields[$language['id_lang']][$field] = '';
		}
	}
	return $fields;
}
}

 

With this code, I get an error when I save the description:

An error occurred while updating object. category ()

 

 

Ps 1.4.8.2.

 

Some help?

Link to comment
Share on other sites

  • 4 weeks later...

Hi all,

 

I have been using this mod for several weeks on my local host and all was working fine.

 

Since I have uploaded my site to the web, it no longer works.

 

The editor and everything seems to wok fine and I can format the description, but when I save the formatted description, all the HTML formatting appears to get stripped during that process.

 

Tried going through the whole process to set it up again but cannot seem to get it working on the live site.

 

I have been using version 1.4.8.2

Link to comment
Share on other sites

  • 3 months later...
  • 1 month later...

I tried the code Bellini13 in Prestashop version 1.5.2 and it works perfectly. Now the category descriptions may contain html tags and I can format the text.

 

thank you very much for the contribution bellini13!

 

Do you have problem with "Read more" button in your category description?

 

If my description is too long a "read more"-button will be displayed... Really annoying.

Do you know have to modify this?

Link to comment
Share on other sites

  • 1 month later...
×
×
  • Create New...