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

Umbraco模板渲染
本文介绍如何使用Umbraco模板渲染当前页面的值或查询缓存的内容。包括两种渲染方式:使用Umbraco Html帮助器和通过视图中的@Model.Content属性。此外,还介绍了如何通过模板查询内容来生成页面导航列表或网站地图。

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值