Thanks Ross, I think I get that.. I'm not seeing the full picture yet,
let me show a bit more of my thinking:

So, extending my previous example, I'd like to write it like this:

<h1>Items</h1>

<lift:Item.firstAndSecond>
<h2><item:which></h2>
<ul>
  <lift:Item.points>
    <li><point:name />
  </lift:Item.points>
</ul>
<lift:item.picture />
</lift:Item.firstAndSecond>

// Emit the block twice, once for each item (first,second).
def firstAndSecond(xhtml: NodeSeq): NodeSeq = {
  List(first,second).flatMap( item => renderItem(xhtml, item) )
}

How then do I implement Item.picture, Item.points to know *which* item
is currently being rendered?

thx

- Alex






On Dec 23, 4:18 pm, Ross Mellgren <[email protected]> wrote:
> S.attr gives you attributes of the current snippet calling tag, e.g.
>
> class Item extends DispatchSnippet {
>      val dispatch: DispatchIt = {
>          case "points" => points
>      }
>
>      def points(ns: NodeSeq): NodeSeq = {
>          val points = S.attr("item") match {
>              case Full("first") => loadFirstListOfPoints()
>              case Full("second") => loadSecondListOfPoints()
>              case _ => error("missing item attribute or has incorrect  
> value")
>          }
>
>          bind(...)
>      }
>
> }
>
> -Ross
>
> On Dec 23, 2009, at 4:07 PM, Alex Black wrote:
>
> > I've got some xhtml blocks in one of my templates that are basically
> > identical, and I'd like to avoid the duplication, by either writing
> > the block once in my template and using a snippet to write it out
> > twice (with different values) or put it in its own template.
>
> > <h1>Items</h1>
>
> > <h2>First</h2>
> > <ul>
> >  <lift:Item.firstPoints>
> >    <li><point:name />
> >  </lift:Item.firstPoints>
> > </ul>
> > <lift:item.firstPicture />
>
> > <h2>Second</h2>
> > <ul>
> >  <lift:Item.secondPoints>
> >    <li><point:name />
> >  </lift:Item.secondPoints>
> > </ul>
> > <lift:item.secondPicture />
>
> > My question is: If I write this block once, and surround it in a
> > snippet which emits it twice, how can the snippet parameterize the
> > nested snippet calls?
>
> > I realize I could bind the entire block with one snippet call, but
> > because my real blocks are big and complex I'd like to keep the many
> > snippet calls per block.
>
> > So, more specifically, how can i write <lift:Item.secondPoints> and
> > <lift:item.firstPoints> more like this: <lift:item.points
> > item="@curItem">
>
> > thx
>
> > - Alex
>
> > --
>
> > You received this message because you are subscribed to the Google  
> > Groups "Lift" group.
> > To post to this group, send email to [email protected].
> > To unsubscribe from this group, send email to 
> > [email protected]
> > .
> > For more options, visit this group 
> > athttp://groups.google.com/group/liftweb?hl=en
> > .

--

You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en.


Reply via email to