是否可以将smarty函数传递给json html输出?

时间:2017-06-22 07:36:26

标签: php jquery json ajax smarty

尝试使用php,smarty和jquery ajax实现无限滚动。据我所知,最好的方法就是这样做而不是加载服务器就像获取json格式的数据一样,并在客户端执行所有过程。问题是我想通过这个聪明的功能。 只是一段带有注释的代码,让您理解我的意思:

$.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>';
}
}

在第二个带注释的示例中,我在浏览器中获取的是+value.comment+而不是注释本身。 我一般对jsonjavascript不满意,也许还有其他一些方式来渲染html以便能够使用smarty函数?谢谢大家!

1 个答案:

答案 0 :(得分:0)

也许value.comment只需要引号:

html += '<p>{"'+value.comment+'"|smarty_modifier_autolink|nl2br|mention}</p>';

看看这个:http://www.smarty.net/docs/en/language.modifiers.tpl

通常在{之后应该有一个聪明的插件,php变量或smarty命令。如果要向内容字符串添加修饰符,则必须用引号括起来。

相关问题