片段可以在提升中获取参数吗? [英] Can snippets take parameters in lift?
问题描述
lift是否有办法将参数传递给摘要?
Is there a way in lift to pass parameters to snippets?
我正在尝试为我的页面编写一个 pluraize 过滤器,该过滤器将显示单词"user"或"users",具体取决于数量:
I am trying to write a pluraize filter for my page that will display the word "user" or "users" depending on how many there are:
1 user
2 users
它在Django中的工作方式称为过滤器,它们的编写方式如下:
The way it works in Django is called filters and they are written as follows:
You have {{ num_messages }} message{{ num_messages|pluralize }}.
所以在这里您可以看到 pluralize 函数采用整数 num_messages 并输出和适当的字符串-空的"或"s".
So here you can see pluralize function takes an integer num_messages and outputs and appropriate string - either empty "" or "s".
请注意,在这种情况下, num_messages 是一个实际的上下文变量,从视图传递到模板.
Note that the num_messages in this case is an actual context variable, passed down to the template from the view.
推荐答案
您可以将参数传递给代码片段,是的.
You can pass parameters to snippets, yes.
class MySnippet {
def foo: NodeSeq = {
x = S.attr("myparam") openOr "myparam: Y U NO DEFINED!?"
<p>I got {x}!</p>
}
}
使用:
<lift:MySnippet.foo myparam="3"/>
或者,较新的Lift 2.3+样式:
Or, newer Lift 2.3+ style:
<div class="lift:MySnippet.foo?myparam=3"/>
这篇关于片段可以在提升中获取参数吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!