Nancy - Super Simple View Engine: How do I override a MasterPage's title in the view?

烈酒焚心 提交于 2019-12-12 15:46:16

问题


I would like to set the title of each rendered page from the corresponding view. I would also like a default title to be set in my Master page. Here is the super-simple set up I am using.

Master Page

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>NancyFX is Splendid</title>
</head>
<body>
    @Section['Content']
</body>
</html>

View

@Master['_Master']
@Section['Content']
    <h1>Home</h1>
    <p>Hello @Model.UserName</p>
@EndSection

I have tried a few of the more obvious guesses but no joy so far. Can you help?

On a more general note - is there any definitive help for Nancy's SSVE? I have read all the docs available on the site and GitHub but they are sparse. Just a list of all SSVE '@[]' keywords, would save me a lot of time.

Thanks


回答1:


You can just render it from the model, same as anything else:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Hello @Model.Name!</title>
</head>
<body>
<h1>Super Simple View Engine</h1>
<p>This text is in the master page, it has access to the model:</p>
<p>Hello @Model.Name!<p>
@Section['Content']
</body>
</html>

As for documentation, most of the tags are documented here: https://github.com/grumpydev/SuperSimpleViewEngine although it's slightly out of date now. It was initially designed purely for internal use, but obviously you are welcome to use it if you want to. The best place to look if you get stuck is the tests, there's samples for all the tags in there.



来源:https://stackoverflow.com/questions/9922691/nancy-super-simple-view-engine-how-do-i-override-a-masterpages-title-in-the

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!