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 ) on the backoffice template editor which can help you pick values and select common modifications:
二,在backoffice模板编辑器中有一个对话框( (click ) ),可以帮助您选择值并做常见的修改:
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 ) in the template editor to build more advanced queries:
您可以使用查询助手(点击),在模板编辑器来构建更高级的查询: