有没有可能动态切换由Lift提供的页面的标题,而不必为该特定情况编写额外的代码片段?
一种选择当然是<lift:mySnippet><title>Default Title</title></lift:mySnippet>,但我认为可能会有类似于<head_merge><title>New Title</title></head_merge> (插入第二个标题节点)的选择。
我不喜欢第一种方法,因为我不想把所有的标题生成逻辑都放在一个单独的代码片段中,并询问我在哪种页面上,等等。
发布于 2011-02-16 02:51:12
你有没有尝试过使用模板?
您可以像这样在templates-hidden/default.html中定义模板:
<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> 并在index.html中使用它,例如:
<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>您可以在此处找到有关模板的更多信息:
http://www.assembla.com/spaces/liftweb/wiki?id=liftweb&wiki_id=Templates_and_Binding
发布于 2011-02-16 20:23:04
一种方法是使用Menu.title代码片段。
在bootstrap/liftweb/Boot.scala中,您可以使用页面名称定义站点地图:
class Boot {
def boot {
// ...
def sitemap = SiteMap(
Menu.i("Home") / "index",
Menu.i("About") / "about")
// ...
}
}在templates-hidden/default.html中,您使用以下代码片段:
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:lift="http://liftweb.net/">
<head>
...
<title class="lift:Menu.title">AppName:</title>
...然后页面标题将是:"AppName: Home“和"AppName: About”。这很好,如果你使用
<span class="lift:Menu.builder"></span>来构建菜单,因为页面标题将与菜单中使用的相同。
另一种方法是使用head merge并在页面的html中定义标题。为此,您必须从templates-hidden/default.html中删除<title>标记,并在内容块中放置一个<head>或<head_merge>标记:
<!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>
...https://stackoverflow.com/questions/5007236
复制相似问题