Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hi Guys I have the following:
Collection
Release 1
Item 1
Item 2
Release 2
When on the collection page
I wanted to find the first release that is not hidden (and published of course) that has child products
so in my collection template I've written the following
<umbraco:Macro runat="server" language="cshtml"> @inherits umbraco.MacroEngines.DynamicNodeContext @{ var activeCollection = Model.Children.Where("Active").XPath("//currentRelease [count(./productItem) > 0]").FirstOrDefault(); if(activeCollection != null && activeCollection.Items.Count() > 0) { var products = activeCollection.Take(15); <div id="collection-items-wrapper" class="clearfix"> <ul class="list-none"> @foreach(var product in products) { <li>@product.Name</li> } </ul> </div> } } </umbraco:Macro>
I'm not getting any results.. just wondering how the XPath query should be formulated and where the "root" of the xpath begins?
Cheers,
Tom
You should be able to do this without using xPath, how about something like this:
dynamic activeCollection = Model.Descendants("releaseDocType").Where("ChildrenAsList.Count > 0").FirstOrDefault();
Obviously changing "releaseDoctype" to whatever you DocType alias is.
The XPath method gives you access to the whole xml cache so those preceding // will start your query from the root node of the cache ie the root node of your site. Try rewriting it to:
XPath("currentRelease [count(./productItem) > 0]")
That should give you the query from your current node - well it worked for me anyhow...
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Razor Xpath statement
Hi Guys I have the following:
Collection
Release 1
Item 1
Item 2
Release 2
Item 1
When on the collection page
I wanted to find the first release that is not hidden (and published of course) that has child products
so in my collection template I've written the following
<umbraco:Macro runat="server" language="cshtml">
@inherits umbraco.MacroEngines.DynamicNodeContext
@{
var activeCollection = Model.Children.Where("Active").XPath("//currentRelease [count(./productItem) > 0]").FirstOrDefault();
if(activeCollection != null && activeCollection.Items.Count() > 0)
{
var products = activeCollection.Take(15);
<div id="collection-items-wrapper" class="clearfix">
<ul class="list-none">
@foreach(var product in products)
{
<li>@product.Name</li>
}
</ul>
</div>
}
}
</umbraco:Macro>
I'm not getting any results.. just wondering how the XPath query should be formulated and where the "root" of the xpath begins?
Cheers,
Tom
You should be able to do this without using xPath, how about something like this:
Obviously changing "releaseDoctype" to whatever you DocType alias is.
The XPath method gives you access to the whole xml cache so those preceding // will start your query from the root node of the cache ie the root node of your site. Try rewriting it to:
XPath("currentRelease [count(./productItem) > 0]")
That should give you the query from your current node - well it worked for me anyhow...
is working on a reply...