Version 5, last updated by dmclean62 at 26 Jan 15:47 UTC

Tricks

1. Using Attributes to make embedding more powerful

I wanted to use an embedded template file in several related circumstances where the behavior was similar but not identical.

  1. Creating a new record from scratch
  2. Editing an existing record

The main template contained this line:


            <f:content></f:content>

Which is handled by this piece from the snippet class:


   bind("f", ns, "content" -> <lift:embed what="/template-editContext" mode="add" />)

Or alternately:


   bind("f", ns, "content" -> <lift:embed what="/template-editContext" mode="modify" contextName="hst1" />)

Part of the template is:


  <lift:EditContext.render>
      <context:header />

Then in the snippet loaded by template-editContext, I have:


     val mode = S.attr("mode").get

and later, I bind some content to the context:header tag:


       bind("context", xhtml, "header" -> <h2>{title(mode)}</h2>)

Where I use the title function to determine which title should be displayed:


 def title(mode: String): String = {
   mode match {
     case "add" => "Add new context"
     case "modify" => "Modifying context: " + editContextName
   }
 }