Add HTML to the Category Description

已回答


已于 2015年2月10日 发布

In the Help Center, I want to add a link (and some other simple HTML) to the description field for just one category (for now). I've read several JS tutorials and examples, but they don't quite fit my situation.

I was able to put my HTML in a placeholder, using Dynamic Content. And I got that to display easily by customizing the "Category Page". But...of course, it is on every page, not just one.

So I'm trying to figure out a way to display my dynamic content on just one particular category page, not all of them. I need some kind of conditional statement or JS. Or....??? 

Hoping someone in Zendesk land can point me in the right direction!


0

22

22 条评论

Amy, that worked! Thank you very much.

0


345556756

Sorry for the late reply. When I first tried this, I had the same problem, and  it was due to an undiagnosed problem with my JS file. Zendesk didn't catch it.

 

When it wasn't working, I ran the JS through a code checker and it identified the problems. Check out this one: https://jslint.com/

Once the error was found and corrected, the code worked. 

This is my code snippet, and it appears before the final });

  //starting custom code
// HTML in section
$(".page-header-description").html($(".page-header-description").text());
$(".category-description").html($(".category-description").text());
$(".section-description").html($(".section-description").text());

 

 

0


Thanks, Amy but I still don't see the html being rendered. Am I doing all the things I need to do? I put the js line in the script.js file:

$('category.description').html( $('category.description').text() );

Then just put tags in the plain text edit field for the category. I didn't change the CSS or anything else.

 

0


819212766 

Try eliminating the <DOCTYPE> <HTML> and <Body> tags and limit to just paragraph and character styles.

0


I tried what has been suggested by placing the JS in the script file: 

 

Next, I tried adding some sample html in a category description. The text is not rendered as expected:

 

I also tried being more specific by using the desc_id as Karl suggested above but this didn't help in my case. Is there something else I need to do? I tested this in Chrome.

 

0


367068348828

I am indeed doing this for section descriptions, although in a different manner. 

I am specific about which ones should use HTML by targeting IDs. I have good reason for doing it like this. 
It works on modern browsers but displays the HTML as plain text in IE11. 

example: 

$('#desc_id_360001778878').html( $('#desc_id_360001778878').text() ); 

 

0


200754043

This is working on my site in Chrome and Explorer. I am only using it on the section page, but I imagine Category should be the same, just replacing section with category.

$('section.description').html( $('section.description').text() );

If it doesn't want on your category, try the section as above and see if that works. If that fails, too, then we might have it narrowed down to your IE settings?

0


11435383488
This solution works good for me in Chrome, but it does not seem to work in Internet Explorer

$('.description').html( $('.description').text() );

If someone knows a fix for that, please let me know.

0


I appreciate the solution, but I don't 100% follow.

The description class is page-header-description.

So I added this to my script.js file.

//Edit HTML in Description of category and section pages
$('page.header.description').html( $('page.header.description').text() );

But as I'm sure you know, it's not working :)

What do I have to do to add line breaks, character formatting, and links to the Descriptions of Sections and Category pages?

 

0


Hoping someone can help - I applied @Rowan fix above and it appears to work, but now I get an error screen at random times (when I don't get the message it actually displays the correct description that has HTML in it):

502 Bad Gateway


nginx

any ideas?

0


帖子评论已关闭。

找不到所需的内容?

新建帖子