Move the bind to an inner function, and call that function  
recursively, for example:

class Image extends DispatchSnippet {
     val dispatch: DispatchIt = {
         case "showAll" => showAll
     }

     def showAll(ns: NodeSeq): NodeSeq = {
         def doBinding(ns: NodeSeq): NodeSeq =
             bind("showAll", ns,
                  "link" -> { (ns: NodeSeq) =>
                      SHtml.link("/viewImage", () => selected(i.id),  
<img src={ i.url } />,
                                 doBinding(ns))
                  })
         doBinding(ns)
     }
}


-Ross


On Dec 23, 2009, at 4:20 PM, Jim Wise wrote:

>
> So, I'm working on a simple image gallery, and I can make a link  
> from an
> image in the gallery to a page for that image with this:
>
>  <lift:Image.showAll>
>    <showAll:imgLink />
>  </lift:Image.showAll>
>
> (additional content omitted for clarity).  This is simple enough to
> bind:
>
>  "imgLink" ->
>    link("/viewImage", () => selected(i.id), <img src={i.url} />)
>
> but this a.) puts a tiny bit of content in the snippet (what if
> different pages want different class attributes on the img tag?), and
> b.) isn't customizable -- if I want another link from the image's  
> name,
> I need another bindpoint, etc.
>
>
> So, with some playing around, I can get a little more general with
>
>  <lift:Image.showAll>
>    <showAll:link>
>      <p>some random html</p>
>    </showAll:link>
>  </lift:Image.showAll>
>
> bound via:
>
>  "link" ->
>    {n: NodeSeq => link("/viewImage", () => selected(i.id), n)}
>
> or:
>
>  "link" -> link("/viewImage", () => selected(i.id),
>      chooseTemplate("showAll", "link", in)),
>
> this works well enough as far as it goes (the latter is a little  
> worse,
> IIUC as it involves more rescanning of the html).
>
>
> But what I would like to do is this:
>
>  <lift:Image.showAll>
>    <showAll:link>
>      <img showAll:imgUrl="" />
>    </showAll:link>
>  </lift:Image.showAll>
>
> and neither of the previous two BindParams work, yielding:
>
>        XML Parsing Error: prefix not bound to a namespace
>        Location: http://www.draga.com:9080/viewImages
>        Line Number 135, Column 12:
>                   <img showAll:imgUrl="" />
>
> since the content is not re-substituted.
>
> So far, the only way I've found to do this is with a second call to
> bind, repeating the list of BindParams:
>
>  "link" ->                    // XXX XXX XXX ugly respecifaction of bind
>     {n: NodeSeq => link("/viewImage", () => selected(i.id),
>       bind("showAll", n,
>        "name" -> i.name.is,
>        AttrBindParam("imgUrl", i.url, "src")
>       ))},
>
> Is there a cleaner way to do this -- to specify that I want bind  
> points
> of this snippet to be evaluated even if they appear within the XML of
> other bind points?  I don't want or need true recursive evaluation --
> just to bind all of the bind points which were visible when the xhtml
> was first parsed.
>
> Thoughts?  This is with 1.1-M8, though I don't think it makes a
> difference...
> -- 
>                               Jim Wise
>                               jw...@draga.com

--

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


Reply via email to