Jump to content

add rich text in category description


Recommended Posts

  • 10 months later...

Hi,
Even I was looking to make the category description in rich text.

The problem is, i want a table to be shown in the category description which is not possible right now.

It would be great if someone could give some guidance on the subject.

Looking forward to some replies.

Thanks in advance.

Hardik

Link to comment
Share on other sites

It is normal for HTML to be stripped from the category description. That is the way Prestashop is currently designed, perhaps because the category description is also used as the tooltip text when hovering over categories in the categories block. You can click on the Bug Tracker link at the top of the page and add a feature request. Hopefully, the Prestashop team will consider adding this feature to a future version.

Link to comment
Share on other sites

  • 3 weeks later...

Hi,
I understand that prestashop uses the description as tooltip, but if i want to show just an information page its really difficult.

Can anyone tell me how i can modify prestashop so that the tags dont get removed. Thanks in advance.

Also, is there a way i can point a category in the category block to an information page created in the CMS. That would be great too.

really looking forward for some help here.

Thanks

Link to comment
Share on other sites

There's a bunch of logic that post-processes the input on the admin side that you don't want to fiddle with.

Presumably this is only one category so as a workaround what you can do is this:

a) Turn off tooltip by editing modules/blockcategories/category-tree-branch.tpl and removing the title stuff.

Get rid of title="{$node.desc|escape:htmlall:'UTF-8'}".

B) Go into phpMyAdmin and edit the table ps_category_lang. Change the description column for the record you want.
For instance, if you change

Wonderful accessories for your iPod

to

Wonderful accessories for your iPod <a href="cms.php?id_cms=5">anchor text

you will create a link to CMS page 5. Just remember that now you can't edit this category in admin->catalog->categories->edit or the HTML will be stripped again.

Link to comment
Share on other sites

i can actually doa script tag and do a window location hack, but thats a bad way to do as on a non-javascript thing it wont work fine.

Some help would be greatly appreciated.

Thanks again ;)

moreover, the bread crumb bar and everything gets disturbed if you direct to a cms page. So what actually must happen is that the the CMS page should load as the product description.

Thanks you for your support.

Link to comment
Share on other sites

  • 3 weeks later...

Hello Hardik,
I'm looking to to the same things you wrote down in this post:
1. Make the category description rich text
2. Link just one category from my categories block to a CMS page

Did you find the way to do it? Or is there a module? I'm not a developer, hope there is a way :)

Link to comment
Share on other sites

I have managed to do it this way

1) As far as the category description in rich text goes, someone on this list suggested that we edit the database directly but that only works for minor changes like you want to add a "mailto" or something small like that. If you want to add a table or something in full blown html it doesnt make sense to edit the database directly as the formatting gets messed up.
a) create a CMS page in the admin panel and make your full html page there
B) link the category you want to that cms page by editing the category.tpl

2) You have to edit the "category-tree-branch.tpl" file. add this just before {if $node.children|@count > 0}
replace node names with the node names of your categories

{if $node.name == "Thread Industry Moulds"}
{$node.name|escape:'htmlall':'UTF-8'}
   {elseif $node.name == "Chilling Plants"}
{$node.name|escape:'htmlall':'UTF-8'}
   {else}
{$node.name|escape:'htmlall':'UTF-8'}

   {/if}



Hope this helps :)

Link to comment
Share on other sites

  • 1 year later...

I have a fairly simple solution for this that only requires minor mods to core files and still displays all of the other category stuff as usual so should be quite useful.

The idea is to create each category description using the CMS tool. By entering the ID of the CMS article in the category description field, we can have the rich content display in the category template. Mods are as follows:

Category.php

//Add CMS to category page////////////////////////
if(is_numeric($category->description)){
$id_cms = $category->description;

$cms = new CMS(intval($id_cms), intval($cookie->id_lang)) AND Validate::isLoadedObject($cms);



   $smarty->assign(array(
       'cms' => $cms,
       'content_only' => intval(Tools::getValue('content_only'))
   ));
}


///////////////////////////////////////////////////



Then to pull it in to the template (category.tpl)


{if $cms}
       {$cms->content}
{else}
       {$category->description}
{/if}



If you want to carry on using the simple text box for some categories, that's fine too as the logic at the start only sets the cms variable if the description is numeric.

Link to comment
Share on other sites

  • 5 months later...

Thanks for the tip, goosedesign. I had to adapt your code in version 1.4. Let me share it with everybody.

In this version, the code should be inserted in /controllers/CategoryController.php in order to make it work. There are some changes in the code also:

//Add CMS to category page////////////////////////
       if(is_numeric($this->category->description)){
           $id_cms = $this->category->description;
           $cms = new CMS((int)($id_cms), self::$cookie->id_lang) AND Validate::isLoadedObject($cms);
           self::$smarty->assign(array(
               'cms' => $cms,
               'content_only' => (int)(Tools::getValue('content_only'))
            ));
       }
///////////////////////////////////////////////////



I put it after this line:

$this->category->description = nl2br2($this->category->description);



The template side (category.tpl) remains the same as described before:

        {if $category->description}

               {if $cms}
                   {$cms->content}
               {else}
                   {$category->description}
               {/if}

       {/if}

Link to comment
Share on other sites

  • 4 weeks later...
Thanks for the tip, goosedesign. I had to adapt your code in version 1.4. Let me share it with everybody.

In this version, the code should be inserted in /controllers/CategoryController.php in order to make it work. There are some changes in the code also:

//Add CMS to category page////////////////////////
       if(is_numeric($this->category->description)){
           $id_cms = $this->category->description;
           $cms = new CMS((int)($id_cms), self::$cookie->id_lang) AND Validate::isLoadedObject($cms);
           self::$smarty->assign(array(
               'cms' => $cms,
               'content_only' => (int)(Tools::getValue('content_only'))
            ));
       }
///////////////////////////////////////////////////



I put it after this line:

$this->category->description = nl2br2($this->category->description);



The template side (category.tpl) remains the same as described before:

        {if $category->description}

               {if $cms}
                   {$cms->content}
               {else}
                   {$category->description}
               {/if}

       {/if}




Hi guys,
This code don't work for me, I've installed prestashop version 1.4.2.
What's wrong? I'm not so good in php...
Link to comment
Share on other sites

Hey, I followed goosedesign but I don't understand how to call the relevant CMS page via the category description?

Currently I'm not inserting any text/numbers in description but a cms page is still showing?!

How do I insert a cms page via the number in the category description? '1' - (1) - {1} etc ??????

Using 1.3.7

Cheers

Link to comment
Share on other sites

How do I insert a cms page via the number in the category description? '1' - (1) - {1} etc ??????

Using 1.3.7


No punctuation should be needed. Just insert the number by itself. I don't know why you would be getting a CMS page without having inserted anything at all. What is the ID of the page that is showing up?
Link to comment
Share on other sites

Hey,

The Secure payment page shows which is 'id_cms=5'.

I have removed everything from the page, including image, description and products but cms=5 is still showing up??

I tried adding a number in description but nothing changes??


Any suggestions??

Cheers

Link to comment
Share on other sites

Hey,

The Secure payment page shows which is 'id_cms=5'.

I have removed everything from the page, including image, description and products but cms=5 is still showing up??

I tried adding a number in description but nothing changes??


Any suggestions??

Cheers


Can you post a link to the page?
Link to comment
Share on other sites

So just to clarify:

1. At present the description for "Lunar Vehicle Tracking Systems" is completely empty, but still you see the content of the CMS page with ID 5 appearing on that category page
2. When you enter another number in that category description, nothing changes

What happens if you enter non-numeric content in the category description?
What happens on other category pages?
Have you tried deleting that secure payment page from the CMS?
Have you looked directly in to the database to see what the entry is for the description for that category?

Link to comment
Share on other sites

1.Yes that is correct

2. Nothing changes except the number showing within the content. This happens on all categories (See attachments)

3.What happens if you enter non-numeric content in the category description?
A: The text is inserted, thats all.

4. What happens on other category pages?
A: All the same.. No difference

5. Have you tried deleting that secure payment page from the CMS?
A:I removed the secure payment page and the contents from the page does not show anymore. I then inserted a number within the description but still no luck?!

6. Have you looked directly in to the database to see what the entry is for the description for that category?
A: No not yet....

Link to comment
Share on other sites

...I'm using prestashop 1.4.2 and this code doesn't work!

The IF part of code work, I mean the number detection work perfectly. (tried with an ECHO under the IF condition)
But for some reason can't load cms instead of description, and still show the number.

Someone can help me?

Link to comment
Share on other sites

Ok, I have tried to resolve my problem but I still cannot get the CMS page to display on the category page via a numeric value placed with the description.....


Previously it was displaying cms=5 on all pages. I removed the cms page and now when data is inserted it is just repeated on the page???

Whats going on?


Could be a stupid question but would running the shop on a localhost make any difference????

46878_8Fj068FWiTxLPMZXbjMX_t

Link to comment
Share on other sites

HI all,
I searched in this forum and finally found a solution to add rich text in categories description:

Here you can find how write html code in description (so you can add bold, links, etc.). For version 1.4.x just see post #51.


And here you can find how insert WYSIWYG editor in category description.



EDIT- The fiules that you can download on first 3d post #51 are yet prepared for showing WYGIWYS editor.
in version 1.4.2 just find this code in AdminCategories.php:

// TinyMCE
       echo '
       < script type="text/javascript" src="'.__PS_BASE_URI__.'js/tinymce/jscripts/tiny_mce/jquery.tinymce.js"></ script>
       < script type="text/javascript">
       function tinyMCEInit(element)
       {
           $().ready(function() {
               $(element).tinymce({
                   // Location of TinyMCE script
                   script_url : \''.__PS_BASE_URI__.'js/tinymce/jscripts/tiny_mce/tiny_mce.js\',
                   // General options
                   theme : "advanced",
                   plugins : "safari,pagebreak,style,layer,table,advimage,advlink,inlinepopups,media,searchreplace,contextmenu,paste,directionality,fullscreen",
                   // Theme options
                   theme_advanced_buttons1 : "newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
                   theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,,|,forecolor,backcolor",
                   theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,media,|,ltr,rtl,|,fullscreen",
                   theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,pagebreak",
                   theme_advanced_toolbar_location : "top",
                   theme_advanced_toolbar_align : "left",
                   theme_advanced_statusbar_location : "bottom",
                   theme_advanced_resizing : false,
                   content_css : "'.__PS_BASE_URI__.'themes/'._THEME_NAME_.'/css/global.css",
                   document_base_url : "'.__PS_BASE_URI__.'",
                   width: "582",
                   height: "auto",
                   font_size_style_values : "8pt, 10pt, 12pt, 14pt, 18pt, 24pt, 36pt",
                   // Drop lists for link/image/media/template dialogs
                   template_external_list_url : "lists/template_list.js",
                   external_link_list_url : "lists/link_list.js",
                   external_image_list_url : "lists/image_list.js",
                   media_external_list_url : "lists/media_list.js",
                   elements : "nourlconvert",
                   convert_urls : false,
                   language : "'.(file_exists(_PS_ROOT_DIR_.'/js/tinymce/jscripts/tiny_mce/langs/'.$iso.'.js') ? $iso : 'en').'"
               });
           });
       }
       tinyMCEInit(\'textarea.rte\');
       </ script>
       ';



And substitute whit this:

       // TinyMCE
       global $cookie;
       $iso = Language::getIsoById((int)($cookie->id_lang));
       $isoTinyMCE = (file_exists(_PS_ROOT_DIR_.'/js/tiny_mce/langs/'.$iso.'.js') ? $iso : 'en');
       $ad = dirname($_SERVER["PHP_SELF"]);
       echo '
           [removed]    
           var iso = \''.$isoTinyMCE.'\' ;
           var pathCSS = \''._THEME_CSS_DIR_.'\' ;
           var ad = \''.$ad.'\' ;
           [removed]
           [removed][removed]
           [removed][removed]';



Welcome Rich Text Editor in categories! ;)

Link to comment
Share on other sites

  • 4 weeks later...
  • 1 month later...
  • 3 weeks later...

Ok something has changed,

so I post the modified files for prestashop 1.4.4, I don't know if works on 1.4.3 too.

Search the originals and substitute both.

 

Hi barba,

 

How do these files differ because i can't see any reference to the CMS ID? and you haven't given any amends to the category.tpl file, so can't see how this will work. Can you give a step by step explanation?

 

Has anyone else got this method working on 1.4.4 yet?

 

Also, can a similar method be used for the new-products.php? I assume it would possibly need to read the id_category from the URL (e.g. http://shop_name.com/new-products.php?id_category=2) and then amend the tpl file to associate each category ID with a CMS ID?

 

Cheers,

 

H

Link to comment
Share on other sites

  • 1 month later...

 

How do these files differ because i can't see any reference to the CMS ID? and you haven't given any amends to the category.tpl file, so can't see how this will work. Can you give a step by step explanation?

 

Has anyone else got this method working on 1.4.4 yet?

 

 

Hollzy I think those files are for using a WYSIWG editor on the category description in the admin, not for using a CMS page as the category description.

 

If anyone ever figures out the original method (ie. how to get the contents of a CMS entry to appear outside of the usual CMS page) for 1.4.x, I'd love to hear it as I think it could also be used to create a simple module that displays the contents of a given CMS page. Could be useful for side boxes or banners.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...