Reputation: 10113
Umbraco Version = 6.0.3
I'm trying to do some seemingly simple stuff in a macro scriptlet. Basically, I want to loop through all of the visible child content that is not a category:
@inherits umbraco.MacroEngines.DynamicNodeContext
@{
var subs = Model.Children.Where("Visible && DocumentTypeAlias != \"Category\"");
}
<span>Count: @subs.Count()</span>
@if (subs.Any())
{
<ul>
@foreach (var sub in subs)
{
<li>
<a href="@sub.Url">@sub.Name</a>
</li>
}
</ul>
}
If I take out the "Visible" portion of the where clause, it works correctly (with the exception of displaying content marked as hidden). I can also use "Visible" on it's own by removing the "DocumentTypeAlias", but then all visible content including categories are displayed.
I also tried using strongly typed queries @Model.Content.Children.Where(x => x.IsVisible() && x.DocumentTypeAlias != "Category")
but I get an error about not being able to use lambda functions with dynamically typed content.
Ideas?
Upvotes: 2
Views: 2081
Reputation: 10922
Two things:
DynamicNode
Where
clause uses a parameter syntax.NodeTypeAlias
to check the document type.Example:
var subs = Model.Children.Where("Visible && NodeTypeAlias != @0", "Category");
Here are a few Umbraco razor resources:
Upvotes: 6