LiftTags

From LiftWiki

Jump to: navigation, search

Here is a rundown of all the known lift tags.


Contents

surround

<lift:surround with="template_name">children</lift:surround>

Uses: Surrounds the child nodes with a named template (located in the /templates-hidden directory of webapp). It is used to apply a unified template to all the page in a site

Demo example:
<lift:surround with="default">
<b>Dude</b>... this is my page... but it'll appear in your browser in a template.
</lift:surround>

Caveats: In the target template there must be a <lift:bind /> tag to indicate where the contents should be bound.

Note that you can use multiple surround templates by adding them to the /templates-hidden directory. For example, you might want to have a separate template for your administrative pages. In that case, you might add that template as admin.html in the /templates-hidden directory and then call it from your other pages using:

<lift:surround with="admin">page code here</lift:surround>

Beware! You cannot have a hidden template with the same name as a sub-directory of your webapp directory. For example, if you had an admin.html template in /templates-hidden, you could not also have an admin directory.

embed

<lift:embed what="template" />

Uses: Allows you to embed a template within another template (or to access a template from a JsCmd such as SetHtml, ModalDialog, etc.)

Note that incoming requests that contain *-hidden in the request will not be serviced, but you can access templates in directories named *-hidden. So, you can put AJAX templates in /ajax-templates-hidden in webapps.

Also, lift's i18n support extends to templates as well, so you can specify "/ajax-templates-hidden/welcome" and lift will serve the appropriate localized template. For example, if the current locale is set to French Canadian lift will look for /ajax-templates-hidden/welcome_fr_CA.html, /ajax-templates-hidden/welcome_fr.html, and /ajax-templates-hidden/welcome.html

Demo example:
<lift:embed what="/ajax-templates-hidden/welcome" />

Caveats: JavaScript contained in templates rendered via JsCmd (sent in response to AJAX requests) will not be executed. This includes Comet Widgets.

comet

<lift:comet type="ClassName" name="optional"/>

Uses:

Demo example:

Caveats: if you have a <lift:comet /> tag and you're using the tag from within sending AJAX stuff back, things might not work well.

ignore

<lift:ignore>children</lift:ignore>

Uses: To have child tags that a browser may parse if the local file is loaded, but should not be included in the rendered code.

This is useful in two areas:

  1. To put comments in the page that should not be rendered out the the browser
  2. To have CSS and other stuff in the page even though the page will be surrounded by a template
Demo example:
<lift:ignore>
<!--
The database info is scott/tiger
-->
</lift:ignore>


Caveats:

snippet

<lift:snippet form="METHOD" type="ClassName:method" multipart="true" />

form and multipart are optional.

Uses:

Demo example:

Caveats:

children

<lift:children>children</lift:children>

Uses: An XML file must contain only 1 root element. If you have a file that contains, for example:

<div>This is the first DIV</div>
<div>This is the other DIV</div>

The file will not parse correctly. So, you can wrap the file in <lift:children/> and the child nodes will be returned.

Stand-alone templates may be returned via <lift:embed what="/ajax-hidden/comfirm-delete"/> in SetHtml and other JsCmds that take a NodeSeq.

Demo example:
<lift:children>
  <div>This is the first DIV</div>
  <div>This is the other DIV</div>
</lift:children>

Caveats:

loc

<lift:loc id="What"/>

Uses:

Demo example:

Caveats:

a

<lift:a>children</lift:a>

Uses: Used internally and should not be used explicitly

Demo example:

Caveats: Don't use it

form

<lift:form method="METHOD" type="ClassName"/>

Uses: Used internally and should not be used explicitly


Demo example:

Caveats: Don't use this tag


with-param/bind-at

Typically in the template-hidden we use <lift:bind name="something"/> to mark the place where we want to render different contents depending on what page are we accessing. On one hand we have:

in the default template:

<lift:bind name="something"/>

<lift:bind name="something-else"/>

in index.html

<lift:surround with="default" >

  ... content 1 ...

  <lift:bind-at name="something">
     ... content 2 ...
  </lift:bind-at>

  ... content 3 ...
 
  <lift:bind-at name="something-else">
     ... content 4 ...
  </lift:bind-at>

  ... content 5 ...

</lift:surrond>

Using bind-at or with-param element we can specify what content goes where when we have multiple bind points.

As you notices <lift:with-param> and <lift:bind-at> are doing exactly the same thing. In time with-param may be deprecated.

Other Notes

head merger

Since version 0.4, it is possible to declare several <head> sections anywhere under body (and its children), and every <head> section will be merged into the /html/head standard location at render time. The head section could be created in the html or in scala code (such as a snippet).

example:

.../webapp/template-hidden/default.html

 <html>
  <head>
    <title>foo</title>
  </head>
  <body>
    <lift:bind name="content" />
  </body>
 </html>

+

.../webapp/index.html

<lift:surround with="default" at="content">
  <head>
    <script src="myscript.js"></script>
    <style>
      ...
    </style>
  </head>
  <h2>Welcome to the your project!</h2>
</lift:surround>

will be renderered like

<html>
  <head>
    <title>foo</title>
    <script src="myscript.js"></script>
    <style>
      ...
    </style>
  </head>
  <body>
    <h2>Welcome to the your project!</h2>
  </body>
</html>

see also ToHeadSpecs

user-defined tag attributes

See [1] for info on adding more attributes to the lift tags, which you can access using the S.attr() function from your snippet code.

more deprecated tags

Personal tools
search|search