[英]Umbraco 7: Get fields from same property based on current page
In my Content section I have a property editor (Archetype) that allows to set content for the site independently from the content tree. 在“内容”部分中,我有一个属性编辑器(Archetype),该编辑器允许独立于内容树来设置网站的内容。 It looks like this:
看起来像这样:
I need to display only the sub categories from one category based on what page I'm currently on. 我只需要根据我当前所在的页面显示一个类别中的子类别。 What I have now is:
我现在所拥有的是:
var catItems = Umbraco.Content(1123).categoryItem; //get the Set Content property editor from Content Section
foreach (var item in catItems)
{
foreach (var sub in item.GetValue<ArchetypeModel>("subCatItem"))
{
<div class="tbl_dt">
<p class="offerName">@sub.GetValue("offerName")</p>
<p class="departurePort">@sub.GetValue("departurePort")</p>
</div>
}
}
This is displaying all the sub category items from all categories. 这将显示所有类别中的所有子类别项目。 It should display only the sub categories based on current page.
它应该仅显示基于当前页面的子类别。 How can I make the connection between current page and the sub category item?
如何在当前页面和子类别项目之间建立连接? Or it is best to stick with the property editor in the content tree pages?
还是最好在内容树页面中使用属性编辑器?
The issue is not the code, but rather the structure of your Content Tree. 问题不是代码,而是内容树的结构。 You have nothing to Associate the Category/Offer to the page you want to display it on.
您没有任何将类别/要约与要在其上显示它的页面相关联。
In order to create an the Association between ContentPage & Category/Offer DocType, you could try one of the following: 为了在ContentPage和Category / Offer DocType之间创建关联,您可以尝试以下操作之一:
Each Page where you want to display the Category/Offer(s) you would need to call the MNTP Picker Property to get the NodeId of that specific Category/Offer for the current page. 要在其中显示类别/要约的每个页面,都需要调用MNTP Picker属性以获取当前页面该特定类别/要约的NodeId。
var catNodeId = @CurrentPage.pickerPropertyAliasHere; //this will give us the NodeId of that specific offer selected for the current page, may need to refactor your code to handle parsing etc.
var catItems = @Umbraco.Content(catNodeId).categoryItem; //Get Categories/Offers from the Offer picked for the current page.
foreach (var item in catItems)
{
foreach (var sub in item.GetValue<ArchetypeModel>("subCatItem"))
{
<div class="tbl_dt">
<p class="offerName">@sub.GetValue("offerName")</p>
<p class="departurePort">@sub.GetValue("departurePort")</p>
</div>
}
}
var catItems = @CurrentPage.categoryItem; //Get Categories/Offers for the current page
foreach (var item in catItems)
{
foreach (var sub in item.GetValue<ArchetypeModel>("subCatItem"))
{
<div class="tbl_dt">
<p class="offerName">@sub.GetValue("offerName")</p>
<p class="departurePort">@sub.GetValue("departurePort")</p>
</div>
}
}
Good Luck C 祝你好运C
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.