Skip to content

页面模板和语法-Page templates and syntax

ARCHIVED

!注意“归档”

This chapter has not been updated for the current version of Orchard, and has been ARCHIVED.

Layout templates are aspx files with includes and calls to helpers.

布局模板是包含和调用帮助程序的aspx文件。

Template markup

模板标记

Currently, we have only content zones, so a template can look like this:

目前,我们只有内容区域,因此模板可能如下所示:

<html>

  <head>

    <link rel="stylesheet" type="text/css"

          href="<%= ResolveUrl("~/Content/StyleSheet.css") %>" />

  </head>

  <body>

    <div class="header">

      <%= Html.Include("header") %>

    </div>

    <div class="centerContentZone">

      <%= Html.IncludeZone("Content") %>

    </div>

    <div class="rightSidebar">

      <%= Html.IncludeZone("Right sidebar") %>

    </div>

    <div class="footer">

      <%= Html.Include("footer") %>

    </div>

    <%= Html.IncludeAdmin() %>

  </body>

</html>

The helpers used above are:

上面使用的助手是:

  • Html.Include(string includeName) includes the partial view whose name is specified.

  • Html.Include(string includeName)包括指定名称的部分视图。 *

  • Html.IncludeZone(string zoneName) includes a named content zone.

  • Html.IncludeZone(string zoneName)包含一个命名的内容区域。 *

  • Html.RenderAdmin() includes the admin link if the user is logged in as administrator.

  • 如果用户以管理员身份登录,则Html.RenderAdmin()包含管理链接。 *

Template Meta-data

模板元数据

Template meta-data is stored directly in the template file as server comments. They are in a simple key-value format. Keys and values are separated by a colon character:

模板元数据作为服务器注释直接存储在模板文件中。它们采用简单的键值格式。键和值由冒号字符分隔:

<%@Page %>

<%--

name: Two column layout

description: This has a main content area and a sidebar on the right.

zones: Content, Right sidebar

author: Jon

--%>

The keys in the meta-data are case-insensitive.

元数据中的键不区分大小写。

Meta-data values can be on multiple lines.

元数据值可以在多行上。

The syntax for meta-data is YAML.

元数据的语法是YAML。

The fields that are not recognized are put in a dictionary so that they are still accessible from code.

将无法识别的字段放入字典中,以便仍可从代码中访问它们。

The last piece of meta-data, which is optional, is the thumbnail representation for it that is used in the template selection screen and in the edit page screen. This is a PNG or GIF image that has the same name as the template file and that is stored in the same directory.

最后一段元数据是可选的,是在模板选择屏幕和编辑页面屏幕中使用的它的缩略图表示。这是一个PNG或GIF图像,与模板文件同名,并存储在同一目录中。