Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to not iterate the whole page in Lift
    text
    copied!<p>How can I bind some variables in Lift, so that I can use them outside the "iterating" part of the template.</p> <p>This is very confusing to me, so I'll pose the question with the help of an example.</p> <p>Let say I have some snippet method that can provide a list of users, and a total count of these users:</p> <pre><code>def users(in: NodeSeq) :NodeSeq={ val (entries:List[User], total:Int) = // read entries and total from somewhere // expensive operation entries.flatMap(user =&gt; Helpers.bind("patient", in, "userID" -&gt; user.userID, "userName" -&gt; user.userName)) </code></pre> <p>now I want to use it within the template: </p> <pre><code>... &lt;lift:Search.users&gt; &lt;tr&gt; &lt;td&gt;&lt;user:userID/&gt;&lt;/td&gt; &lt;td&gt;&lt;user:userName/&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/lift:Search.users&gt; ... </code></pre> <p>However, I also want to output the <strong>total</strong> count of users - but somewhere else on the page:</p> <pre><code>&lt;b&gt;Total users: &lt;user:total&gt;&lt;/b&gt; &lt;--- ????? ... &lt;lift:Search.users&gt; &lt;tr&gt; &lt;td&gt;&lt;user:userID/&gt;&lt;/td&gt; &lt;td&gt;&lt;user:userName/&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/lift:Search.users&gt; ... </code></pre> <p>as you can imagine this does not work, because it is outside the <strong>Search</strong> snippet tag. Furthermore - if I try to <em>bind</em> the total to <em>users</em> - it unbinds all my previous binds for the user!</p> <p>I tried putting the lift tags around the whole document, but that just makes the whole page repeat itself!!</p> <pre><code>&lt;body&gt; &lt;lift:Search.users&gt; &lt;---- clones the whole page! &lt;b&gt;Total users: &lt;user:total&gt;&lt;/b&gt; &lt;table&gt; ... &lt;tr&gt; &lt;td&gt;&lt;user:userID/&gt;&lt;/td&gt; &lt;td&gt;&lt;user:userName/&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/lift:Search.users&gt; &lt;/body&gt; </code></pre> <p>I am new to Lift - so I must be missing something really obvious.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload