Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing <title> with Lift

Is it possible to dynamically switch the title of a page that is served by Lift without having to write an extra snippet for that particular case?

One option is of course <lift:mySnippet><title>Default Title</title></lift:mySnippet> but I thought there might be an option along the lines of <head_merge><title>New Title</title></head_merge> (which inserts a second title node).

I do not like the first approach since I do not want to stick all the title generation logic into a single snippet and ask what kind of page I am on etc.

like image 407
Joa Ebert Avatar asked Jan 20 '23 11:01

Joa Ebert


1 Answers

Have you tried to use templates?

You can define template in templates-hidden/default.html like this:

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:lift="http://liftweb.net/">

    <head>
        <title>
            <lift:bind name="title" />
        </title>

        ...
    </head>

    <body>
        <lift:bind name="content" />
    </body>
</html> 

And use it in index.html for example:

<lift:surround with="default">
    <lift:bind-at name="title">Home</lift:bind-at>
    <lift:bind-at name="content">
        my content
    </lift:bind-at>
</lift:surround>

You can find more information about templates here:

http://www.assembla.com/spaces/liftweb/wiki?id=liftweb&wiki_id=Templates_and_Binding

like image 155
tenshi Avatar answered Jan 28 '23 09:01

tenshi