【问题标题】:Setting Super Simple View Engine Sections in from nested master pages从嵌套母版页中设置超级简单的视图引擎部分
【发布时间】:2017-03-20 11:00:15
【问题描述】:

我正在构建一个 Web 应用程序,并使用 Nancy 和 Super Simple 视图引擎为用户呈现内容。由于许多页面具有相同的布局(标题、侧边菜单等),因此我在母版页中分离了可重复使用的内容。

目前我有

--Root_file (Master page)
   --Home
   --Products
   --Contact
   --Account (Master page)
     --Overview
     --Manage
     --Post

root_file 下的所有文件都有一个@Master['root_file.html'] 引用。 Account 下的所有文件都有一个@Master['account.html']

现在我的问题是,对于帐户下的管理,我想将 js 脚本设置为附加标头。我想,通过引用顶级母版页中的标签,我可以通过引用添加js。

这是一个概述。

Root_file.html
<head>
    <title>Nice little title.</title>
    @Partial['PartialView/header_references.html']
    @Section['Additional_headers'];
</head>
<body>
    @Section['Content'];
</body>

account.html
@Master['root_file.html']

@Section['Content']
    <div class="container">
        <div class="row justify-content-center">
            @Partial['PartialView/side_menu.html']
            <div class="col p-3">
                @Section['Inner_content'];
            </div>
        </div>
    </div>
@EndSection

manage.html
@Master['account/overview.html']
@Section['Additional_headers']
    <script src="../../../Content/scripts/file-upload.js"></script>
@EndSection

我希望我可以通过嵌套母版页设置@Section[Additional_headers],但结果并没有反映我的希望。

是我做错了什么,还是不能设置这样的部分?

【问题讨论】:

    标签: nancy viewengine


    【解决方案1】:

    这是一个老问题,我想你在别处得到了答案,但也许其他人也有同样的问题。 我最终用子页面中的新占位符包装了顶部母版页的占位符。它一点也不漂亮,但它完成了工作。

    在你的html页面中引用

    @Section['Additional_headers']
    

    相反,您可以在包含在新占位符中的子母版页中引用它,例如:

    @Section['Additional_headers']
    @Section['Sub_Additional_headers']
    @EndSection
    

    然后您可以在像这样的任何底层 html 页面中引用这个新部分

    @Section['Sub_Additional_headers']
    <label>This is in a nested master page</label>
    @EndSection
    

    要重复使用上面的示例,它看起来像这样

    Root_file.html
    <head>
        <title>Nice little title.</title>
        @Partial['PartialView/header_references.html']
        @Section['Additional_headers'];
    </head>
    <body>
    @Section['Content'];
    </body>
    
    account.html
    @Master['root_file.html']
    
    @Section['Additional_headers']
    @Section['Sub_Additional_headers']
    @EndSection
    
    @Section['Content']
    <div class="container">
        <div class="row justify-content-center">
            @Partial['PartialView/side_menu.html']
            <div class="col p-3">
                @Section['Inner_content'];
            </div>
        </div>
    </div>
    @EndSection
    
    manage.html
    @Master['account/overview.html']
    @Section['Sub_Additional_headers']
    <script src="../../../Content/scripts/file-upload.js"></script>
    @EndSection
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多