Changing <title> with Lift

Is it possible to dynamically switch the title of the page served by the elevator, without the need to write an additional fragment for this particular case?

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

I don’t like the first approach, since I don’t want to embed all the header generation logic in one fragment and ask which page I am on, etc.

+4
source share
2 answers

Have you tried using patterns?

You can define a template in templates-hidden/default.html as follows:

 <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> 

More information on templates can be found here:

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

+8
source

One way is to use the Menu.title .

In bootstrap/liftweb/Boot.scala you define a site map with page names:

 class Boot { def boot { // ... def sitemap = SiteMap( Menu.i("Home") / "index", Menu.i("About") / "about") // ... } } 

In templates-hidden/default.html you use the snippet:

 <html xmlns="http://www.w3.org/1999/xhtml" xmlns:lift="http://liftweb.net/"> <head> ... <title class="lift:Menu.title">AppName:</title> ... 

Then the page names will be: "AppName: Home" and "AppName: About". It is good if you use

 <span class="lift:Menu.builder"></span> 

to create a menu because the page names will be the same in the menu.

Another approach is to use head merge and define the title on the html page. To do this, you need to remove the <title> from templates-hidden/default.html and place the <head> or <head_merge> in your content block:

 <!DOCTYPE html> <html> <body class="lift:content_id=main"> <div id="main" class="lift:surround?with=default;at=content"> <head_merge> <title>TITLE OF THIS PAGE HERE</title> </head_merge> ... 
+1
source

Source: https://habr.com/ru/post/1339856/


All Articles