0
votes

I am using play framework 1.4.x, In controller , render a List object like this

List<Article> articles = Article.find("Category = ? order by id desc", cateId).fetch();
render(articles)

In views,html template

%{ for (item in articles) { }%
<div>
 ${item.title}
<li>${item.description}</li>
</div>
%{ } }%

but, the description is to long, need to do some kind of string format,or cut work,then show in the template. I have already google for the template syntax but got nothing.

thanks for @Md Ayub Ali Sarker. but I write a pure scala function in template , It throws a template compilation error.

It throws a template compilation error

It has fixed. 1.you can define a function in somewhere like utils. 2.in the views template,you can use these code call the utils function

%{hasBeenCuted = utils.Cut.cut(oginalKeywordsNeedToCut)}%
${hasBeenCuted}
1

1 Answers

0
votes

write template function in pure Scala code like

 @shortdescription(text: String) = @{
  text.take(10); // take first 10 character // more scala string function http://alvinalexander.com/scala/scala-string-examples-collection-cheat-sheet
}

in view change like this

%{ for (item in articles) { }%
<div>
 ${item.title}
<li>@shortdescription(${item.description})</li>
</div>
%{ } }%