Umbraco 官方技术文档 翻译 九、 Rendering content 呈现内容

来源:互联网 发布:mac 邮件登录企业邮箱 编辑:程序博客网 时间:2024/06/01 15:51

Rendering content

呈现内容

The primary task of any template in Umbraco is to render the values of the current page or the result of query against the content cache.
任何Umbraco模板的主要任务都是是显示当前页面的值或查询结果缓存的内容

Rendering values

显示值

Values of the current page can be rendered in 2 different ways, either by using the Umbraco html helper, which lets you access each field by its alias like so:
当前页面的值有两个不同的呈现方式,一,通过使用Umbraco html帮助,它可以让你通过别名来访问每个字段:

</pre><pre name="code" class="html"><h1>Hello @Umbraco.Field("pageName")</h1><p>@Umbraco.Field("bodyText")</p>

There is a dialog (click Button) on the backoffice template editor which can help you pick values and select common modifications:
二,在backoffice模板编辑器中有一个对话框( (click Button) ),可以帮助您选择值并做常见的修改:

Dialog

Rendering a field with Model

呈现模型的字段

The UmbracoHelper method provides many useful parameters to change how the value is rendered. If you however simply want to render value “as-is” you can use the@Model.Content property of the view. For example:
UmbracoHelper方法提供了许多有用的参数来改变要呈现的值。如果你只是想“原样”呈现内容,可以视图中使用@Model.Content属性 。例如:

@Model.Content.GetPropertyValue("bodyContent")

You can also specify the output type that you want from the property. If the property editor or value does not support the conversion then an exception will be thrown. Some examples:
您还可以指定您想要的属性的输出类型。如果属性或值不支持转换,将抛出一个异常。比如:

@Model.Content.GetPropertyValue<double>("amount")

Query content

查询内容

In many cases, you want to do more then just display values from the current page, like creating a list of pages in a navigation - or generate a sitemap. You can do this by querying content in your templates:
在许多情况下,你想要做就是从当前页面显示值 ,比如创建一个页面导航列表, 或者生成网站地图。你可以通过模板中的查询内容做到:

<ul>    @foreach(var child in Model.Content.Children())    {        <li><a href="@child.Url">@child.Name</a></li>    }</ul>

You can use the query helper (click Query button) in the template editor to build more advanced queries:
您可以使用查询助手(点击Query button),在模板编辑器来构建更高级的查询:

Query helper

More information

  • Razor examples
  • Querying

Umbraco TV

  • Episode: Setting up our first template
  • Episode: Insert Umbraco page field dialog
0 0
原创粉丝点击