Quantcast

can I do something like this with nested snippets?

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

can I do something like this with nested snippets?

george-159

<lift:Licenses.index>

        <h3><l:type /></h3>

        <table>
                        <lift:Ratings.index>
                        <tr>
              <td><r:rating /></td>
                        </tr>
                        </lift:Ratings.index>
        </table>

</lift:Licenses.index>


and if so..

can I pass a parameter to the inner Ratings.index snippet - e.g the ID
of the current license object being processed - so that the
Ratings.index function can use it to find the ratings.

the idea being that this way I could re-use my existing Rating snippet
code to display ratings on the same page as licenses. or is this just
a bad idea?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Lift" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/liftweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: can I do something like this with nested snippets?

Naftoli Gugenheim
Try (not sure if this is the correct syntax for snippet attributes):
<lift:Licenses.index>

       <h3><l:type /></h3>

       <table>
                       <lift:Ratings.index lift:Licenses.id="">
                       <tr>
             <td><r:rating /></td>
                       </tr>
                       </lift:Ratings.index>
       </table>

</lift:Licenses.index>

Then you need an attribute snippet Licenses.id which generates MetaData (xml attributes), and then Ratings.index needs to call S.attr to read the attribute.
I haven't tried doing this but this is my understanding.



On Tue, Aug 25, 2009 at 4:21 PM, george <[hidden email]> wrote:
<lift:Licenses.index>

       <h3><l:type /></h3>

       <table>
                       <lift:Ratings.index>
                       <tr>
             <td><r:rating /></td>
                       </tr>
                       </lift:Ratings.index>
       </table>

</lift:Licenses.index>


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

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: can I do something like this with nested snippets?

george-159

That seems to make sense mostly. I'll give it a try.

One thing I am not sure about is this:

As the License.index is iterating over the licenses, when I call
License.id how will the License snippet know which is the current
object? Do I have to maintain a reference to it somewhere?

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

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: can I do something like this with nested snippets?

Naftoli Gugenheim
Yes, either in a RequestVar or make License a StatefulSnippet and use a regular class var.

On Tue, Aug 25, 2009 at 4:43 PM, george <[hidden email]> wrote:

That seems to make sense mostly. I'll give it a try.

One thing I am not sure about is this:

As the License.index is iterating over the licenses, when I call
License.id how will the License snippet know which is the current
object? Do I have to maintain a reference to it somewhere?

Thanks



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

dpp
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: can I do something like this with nested snippets?

dpp
In reply to this post by george-159


On Tue, Aug 25, 2009 at 1:21 PM, george <[hidden email]> wrote:

<lift:Licenses.index>

       <h3><l:type /></h3>

       <table>
                       <lift:Ratings.index>
                       <tr>
             <td><r:rating /></td>
                       </tr>
                       </lift:Ratings.index>
       </table>

</lift:Licenses.index>


and if so..

can I pass a parameter to the inner Ratings.index snippet - e.g the ID
of the current license object being processed - so that the
Ratings.index function can use it to find the ratings.

the idea being that this way I could re-use my existing Rating snippet
code to display ratings on the same page as licenses. or is this just
a bad idea?

Lift snippets are evaluated lazily.  What this means is that you'll get

<h3><l:type /></h3>

       <table>
                       <lift:Ratings.index>
                       <tr>
             <td><r:rating /></td>
                       </tr>
                       </lift:Ratings.index>
       </table>

Passed to the Licenses.index snippet.  Your snippet may choose to return the xhtml bound or it may choose to evaluate the inner part as well:

object CurrentLicense extends scala.util.DynamicVariable[Box[License]](Empty)

class Licenses {
  def index(xhmtl: NodeSeq): NodeSeq = {
   val currentLicense = calcLicense
   for {
     session <- S.session.toList
     val bound = bind("l", xhtml, "type" -> currentLicense.theType)
     node <- CurrentLicense.withValue(Full(currentLicense)){session.processSurroundAndInclude(PageName get, bound)}
   } yield node
  }
}

In the Ratings snippet, you just have to get the current license from the CurrentLicense DynamicVariable.
 





--
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Git some: http://github.com/dpp

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

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: can I do something like this with nested snippets?

george-159

David - thanks for this.

I understand most of what is going on here.

I've not come across DynamicVariable before, but having looked it up I
think I see why you have used it.

Please could you explain a bit more what is happening in this line:

CurrentLicense.withValue(Full(currentLicense))
{session.processSurroundAndInclude(PageName get, bound)}

What/where is PageName get ?

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

dpp
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: can I do something like this with nested snippets?

dpp


On Tue, Aug 25, 2009 at 3:09 PM, george <[hidden email]> wrote:

David - thanks for this.

I understand most of what is going on here.

I've not come across DynamicVariable before, but having looked it up I
think I see why you have used it.

Please could you explain a bit more what is happening in this line:

CurrentLicense.withValue(Full(currentLicense))
{session.processSurroundAndInclude(PageName get, bound)}

What/where is PageName get ?

It's a RequestVar in LiftSession.scala
 






--
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Git some: http://github.com/dpp

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

Loading...