Is there a way in lift to pass parameters to snippets?
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
The way it works in Django is called filters and they are written as follows:
You have {{ num_messages }} message{{ num_messages|pluralize }}.
So here you can see pluralize function takes an integer num_messages and outputs and appropriate string - either empty "" or "s".
EDIT: 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>
}
}
Use:
<lift:MySnippet.foo myparam="3"/>
Or, newer Lift 2.3+ style:
<div class="lift:MySnippet.foo?myparam=3"/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With