Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Those are old-style tags, not designer-friendly tags.</p> <pre><code>&lt;lift:MySnippet&gt; &lt;b:field /&gt; &lt;/lift:MySnippet&gt; </code></pre> <p>becomes</p> <pre><code>&lt;div class="lift:MySnippet"&gt; &lt;div class="field"&gt;&lt;/div&gt; &lt;/div&gt; </code></pre> <p>Old-style Lift templates are valid XML, not XHTML - so you can't have unclosed tags or anything - this differentiates Lift from most frameworks, which treat templates as raw strings with bits of code intertwined throughout, without regard to tags or structure.</p> <p>BTW, in old-style tags, those fields are all fabricated - they aren't part of some standard set of Lift tags. I could just as easily do:</p> <pre><code>&lt;lift:MySnippet&gt; &lt;frobnicate:blorb /&gt; &lt;/lift:MySnippet&gt; </code></pre> <p>as long as my snippet code is looking for that specific tag.</p> <p>Lift doesn't allow <em>any</em> logic in your templates. All of the logic happens in your Snippet class. So for the designer-friendly example above, I might have a snippet class like this:</p> <pre><code> class MySnippet { def render(in: NodeSeq): NodeSeq = ".field" #&gt; Text("some text here") } </code></pre> <p>which would yield this result:</p> <pre><code> &lt;div&gt; &lt;div class="field"&gt;some text here&lt;/div&gt; &lt;/div&gt; </code></pre> <p>It's impossible to put any logic in Lift templates - all they can do is invoke Lift snippets, which are regular Scala classes where all of the work happens.</p> <p>Lift discards the rule that you shouldn't have any display logic in your real code. Why? Because it makes for more reusable code, because Scala has powerful XML support baked into the language and because all of your logic is now treated as plain old Scala code.</p> <p>If I define a Lift snippet called <code>CurrentTime</code>, I can simply drop that in to any template and it will display the current time - with old-school MVC frameworks, each action method needs to set the time as a page variable and then my templates would need to be modified to print it out. For more complicated logic, old-school frameworks would probably require a conditional in the templates. Lift doesn't allow that - all of your logic is regular Scala code, eligible for refactoring, easily testable, and compatible with modern IDE's.</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