- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-19-2016 07:24 AM
For CMS, trying to display all knowledge articles in a single page. So, creating a new page from scratch using jelly. I want to display two lines of the articles text for each knowledge article. How to extract the text only from the html text field? where can I find the script?
Right now it is like this,
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-27-2016 03:49 PM
Hi Rajini,
htmlText.stripScripts().stripTags(); is not working on <hr/> and <br/> but working on <hr> so I guess yes. let us use the regular expression as well. it will work.
function removeHTMLTagsCMS(inputId, divId){
var htmlText = $(inputId).getValue();
htmlText = htmlText.stripScripts().stripTags(); // prototype methods to strip tags and strip scripts
htmlText=htmlText.replace(/<(?:.|\s)*?>/g, " ");
$(divId).update(htmlText) ;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-19-2016 08:42 AM
Hi Rajini,
If you are using Knowledge Base version lesser than 3 then it would be the macro kb_article_header but if you are using version KB Version 3, it is generally automatic once you have the content in the article it pulls the first few lines. And since that is a out of the box feature it should work if you are using the knowledge base block in CMS.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-19-2016 08:55 AM
I have this jelly script, trying to pull only the two lines of article text without html tags. Its not working, need help with this.
<div>
<g:evaluate var="jvar_article_text" jelly="true">
var regex = /(${AMP}nbsp;|${AMP}lt;([^${AMP}gt;]+)${AMP}gt;)/ig
var article = "${kb.text}";
var article_text = article.replace(regex, "");
article_text;
</g:evaluate>
<span>${jvar_article_text}</span>
</div>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-19-2016 09:10 AM
Hi Rajini,
Did you check your regex in browser to see if it is working correctly. Alternatively, you can use these approaches:-
1. Replace the regular expression you have with /<(?:.|\n)*?>/gm to see if it picks up
2. Or you can use the browser as well by creating a dom element assigning the string to the inner html and then grabbing the inner text of the element.
But apart from that also log to see if {kb.text} as far as i remember it is a translated html field so you might want to use {kb.text.getDisplayValue()}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-19-2016 09:27 AM
Jelly script actually worked for simple html tags like example: <p>Adding some text here.</p>
But, when there is too much of complex html code, it returns null. I think the double quotes and & characters within HTML are breaking it.
<div>
<g:evaluate var="jvar_article_text" jelly="true">
var regex = /${AMP}lt;(?:.|\n)*?${AMP}gt;/gm
var article = "${kb.text.getDisplayValue()}";
var article_text = article.replace(regex, "");
article_text;
</g:evaluate>
<span>${jvar_article_text}</span>
</div>