Embedding snippets & CSS selectors

28 views
Skip to first unread message

Tobias Pfeiffer

unread,
Jan 26, 2012, 8:50:04 AM1/26/12
to lif...@googlegroups.com
Hi,

in many places of my templates, I use similar HTML code to display
information, like

<div class="list:someSnippet.listPosts">
<div class="post">
<p><b class="title">Post title goes here</b><br/>
<span class="body">Post body goes here</span></p>
</div>
</div>

However, the actual snippet method that's called is different, like
someSnippet.listPosts, someSnippet.listRelatedPosts,
someSnippet.listDeletedPosts etc., and I was wondering how to externalize
the HTML <div class="post">...</div>.

I tried to put that code into a template file _post.html and then use

<div class="lift:embed?what=_post"></div>

everywhere where it appeared before. However, it seems as if my CSS
selectors in the snippet

".title" #> ...

don't work any more, as I now get the actual HTML from the _post.html, i.e.
without the replaced data in it.

What's the way to go here in order to not repeat the HTML again and again?

Thanks for your help
Tobias

signature.asc

Jeppe Nejsum Madsen

unread,
Jan 26, 2012, 9:03:25 AM1/26/12
to lif...@googlegroups.com

Lift's templates are by default evaluated outside-in, which means the
embed is not evaluated before the transforms kick-in.

Several possible options described here:

http://groups.google.com/group/liftweb/browse_frm/thread/7d9ba4955b55d16/bd6bf945536a1ed0?

/Jeppe

John Bruce

unread,
Jan 26, 2012, 9:16:00 AM1/26/12
to lif...@googlegroups.com
Hi Tobias,

Not sure if this the right way to do it but one option could be to put
the <div class="post"> etc html code in a hideen template. Then create
a method that take a list of posts and uses S.runTemplate to return a
Box[NodeSeq] that you can use in your snippets.

Cheers,

John

Andreas Joseph Krogh

unread,
Jan 26, 2012, 10:02:25 AM1/26/12
to lif...@googlegroups.com

You may use eager_eval which forces eager-eval of the embedded snippet:
<div class="lift:MySnippet?eager_eval=true">


<div class="lift:embed?what=_post"></div>

</div>

--
Andreas Joseph Krogh <and...@officenet.no> - mob: +47 909 56 963
Senior Software Developer / CTO - OfficeNet AS - http://www.officenet.no
Public key: http://home.officenet.no/~andreak/public_key.asc

Tobias Pfeiffer

unread,
Jan 26, 2012, 10:09:19 AM1/26/12
to lif...@googlegroups.com
Hi,

Am Donnerstag, 26. Januar 2012, 16:02:25 schrieb Andreas Joseph Krogh:
> You may use eager_eval which forces eager-eval of the embedded snippet:
> <div class="lift:MySnippet?eager_eval=true">
> <div class="lift:embed?what=_post"></div>
> </div>

Thanks for all the suggestions, just adding the eager_eval parameter to the
outer snippet worked fine. Very good :-)

Kind regards
Tobias

signature.asc
Reply all
Reply to author
Forward
0 new messages