umbraco razor - 从内容中获取字段 [英] umbraco razor - getting fields from content
问题描述
我有 6 个相同内容类型新闻"的项目,在每个项目中我有一个字段 newsIntro.我想将特定页面中的字段放在另一个页面上,所以我需要定位一个特定字段,因此它可能是节点 1702 上的 newsIntro.我尝试了一些类似
I have a 6 items of the same content type "news", in each item I have a field newsIntro. I want to put the fields in specific pages on another page so I need to target a specific field so it may be newsIntro on node 1702. I have tried a few things like
@1720.newsIntro
@1720.newsIntro
如何定位特定领域
谢谢
推荐答案
在学习 Razor 时,您应该查看一些很棒的资源:
There are some great resources you should take a look at while you are learning Razor:
Umbraco Razor 功能演练 - 包含示例的八部分博客文章系列,包含 Umbraco 4.7 中的许多 Razor 新功能.
Umbraco Razor Feature Walkthrough - An eight part blog post series of many of the new Razor features in Umbraco 4.7 with examples.
Razor DynamicNode 备忘单 -Razor DynamicNode
对象(包括 @Model
)可用的所有属性和方法的 PDF.
Razor DynamicNode Cheat Sheet - A PDF of all the properties and methods available to the Razor DynamicNode
object (that includes @Model
).
Cultiv Razor 示例 - Umbraco 网站您可以下载并使用 WebMatrix 或 IIS 打开,并查看使用 Razor 访问属性的各种方法.
Cultiv Razor Examples - An Umbraco website that you can download and open with WebMatrix or IIS and see various ways to access properties with Razor.
Razor 片段 - 不同的汇编来自 Our Umbraco 的片段、示例等.
Razor snippets - A compilation of different snippets, examples, etc. from Our Umbraco.
但是在回答您的问题时,要获取特定节点的属性,您必须先获取实际的 DynamicNode
对象,然后使用属性别名来访问属性值.示例:
But in answer to your question, to get a property of a specific node you have to get the actual DynamicNode
object first, then use the property alias to access the property value. Example:
@{
//Get the node
dynamic node = Library.NodeById(1720);
// Display the property
@node.newsIntro
}
要从当前页面访问属性,只需使用 Model
:
To access a property from the current page, you simply use Model
:
@Model.newsIntro
或
@Model.bodyText
或
@Model.Name
这篇关于umbraco razor - 从内容中获取字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!