我是Handlebars模板系统的新手,这是我使用Handlebars工作的第一个项目。我创建了简单的模板:Handlebars - substring
<script id="article_list_template" type="text/x-handlebars-template">
{{#each this}}
<div class='article'>
<a href='article.php?id={{id_news}}' data-article_id='{{id_news}}'>
<h1>{{title}}</h1>
</a>
<p> {{{content}}} </p>
<div style='clear: both;'> </div>
</div>
{{/each}}
</script>
返回content
很长。我希望它比较短,例如150个字符。我试图使用JavaScript substring()
方法如下:
<p> {{{content.substring(0,150)}}} </p>
但它显然没有奏效。你能给我一些提示如何处理这个问题。由于
编辑: 好了,问题就解决了: 我在PHP做了,使返回的内容现在已经适当的长度:
foreach ($articles as $a) {
$a->content = cut_text($a->content, 30);
}
要关闭的问题,提出解决方案,并接受它作为一个答案。 – craniumonempty 2012-04-13 12:03:16