Trying to implement infinite scroll, with php, smarty and jquery ajax. As I understood best way to do so and not load server much is getting response as json formatted data, and do the all process on the client side. The thing is that I would like to pass smarty functions in that. Just a piece of code with comments for you to understand what I mean:
$.each(data.content, function(key, value ){
if(value.comment !=''){
//When it comes to date, smarty is working and is implementing date_format
html += '<div class="timeline-date"><i class="fa fa-calendar"></i>
{'+value.date+'|date_format:"%B %d, %Y %I:%M %p"}</div>';
html += '</div>';
//But when it comes to comment itself, smarty functions are not working
html += '<p>{'+value.comment+'|smarty_modifier_autolink|nl2br|mention}</p>';
}
}
In second example with comment all I get in browser is +value.comment+
instead of the comment itself.
I'm not strong with json
or javascript
in general, maybe there is some other way to render html to make it possible to use smarty
functions? Thanks everyone!
Maybe value.comment
just needs quotes:
html += '<p>{"'+value.comment+'"|smarty_modifier_autolink|nl2br|mention}</p>';
Have a look at this: http://www.smarty.net/docs/en/language.modifiers.tpl
Normally after {
there should be a smarty plugin, php variable or smarty command. If you want to add a modifier to a content string then you have to surround it by quotes.