Hy i'm using latest MacroEngines Build. Now the problem.
I do the following with my code:
@{ var start = Model.AncestorOrSelf(1).Descendants("FolderArticles"); var articles = start.Descendants("articlePost"); } @foreach(var c in articles) { <h2>@n.contentTitle</h2>... }
But it's throwing an error umbraco.MacroEngines.DynamicNodeList' does not contain a definition for 'Descendants'
The reason your code doesnt work is because you call Descendants() in the first line which gives you a DynamicNodeList, then you call Decendants on that. I assume that you only have a single FolderArticles node right?
If so, you need to do something like this...
@{
// get current node var current = new DynamicNode(Model.Id)
// get a single FolderArticles node var start = current.AncestorOrSelf(1).Descendants("FolderArticles").Items.Single();
// get descendants of type articlePost var articles = start.Items.Descendants("articlePost"); }
@foreach(var c in articles) { <h2>@n.contentTitle</h2>... }
If you have multiple FolderArticle nodes then you need to iterate over all of them.
Error loading Razor Script TabTest.cshtml c:\inetpub\wwwroot\kultmark\macroScripts\TabTest.cshtml(19): error CS1061: 'object' does not contain a definition for 'nodeName' and no extension method 'nodeName' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)
Where do you have the input from with the .Items.Single() never read about this before.
DynamicNodeProblem 4.7.1
Hy i'm using latest MacroEngines Build. Now the problem.
I do the following with my code:
@{
var start = Model.AncestorOrSelf(1).Descendants("FolderArticles");
var articles = start.Descendants("articlePost");
}
@foreach(var c in articles)
{
<h2>@n.contentTitle</h2>...
}
But it's throwing an error umbraco.MacroEngines.DynamicNodeList' does not contain a definition for 'Descendants'
Some ideas? Looked through the Wiki @ http://our.umbraco.org/wiki/reference/code-snippets/razor-snippets/dynamicnode-%28and-model%29-members-and-properties and there i see it should be possible to acces Descendants from DynamicNodeList
Tested this but wont work:
@using umbraco.MacroEngines
@using System.Linq
@using System.Xml.Linq
@{
var nodes = Model.AncestorOrSelf(1).Descendants("FolderArticle");
}
@foreach(dynamic news in ((DynamicNodeList)nodes).myArticle)
{
foreach(dynamic n in news)
{
<p>@n.Url</p>
}
}
The reason your code doesnt work is because you call Descendants() in the first line which gives you a DynamicNodeList, then you call Decendants on that. I assume that you only have a single FolderArticles node right?
If so, you need to do something like this...
@{
// get current node
var current = new DynamicNode(Model.Id)
// get a single FolderArticles node
var start = current.AncestorOrSelf(1).Descendants("FolderArticles").Items.Single();
// get descendants of type articlePost
var articles = start.Items.Descendants("articlePost");
}
@foreach(var c in articles)
{
<h2>@n.contentTitle</h2>...
}
If you have multiple FolderArticle nodes then you need to iterate over all of them.
Hope that helps.
ps. you should rename articlePost to ArticlePost.
Hmm won't work, throws an error:
Error loading Razor Script TabTest.cshtml
c:\inetpub\wwwroot\kultmark\macroScripts\TabTest.cshtml(19): error CS1061: 'object' does not contain a definition for 'nodeName' and no extension method 'nodeName' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)
Where do you have the input from with the .Items.Single() never read about this before.
Greetings
You're now using a DynamicNode object
Sorry n.contentTitle should be n.GetProperty("contentTitle")
You also need using System.Linq
Can you paste your script?
@using umbraco.MacroEngines
@using System.Linq
@using System.Xml.Linq
@{
// get current node
var current = new DynamicNode(Model.Id)
// get a single FolderArticles node
var start = current.AncestorOrSelf(1).Descendants("FolderArticlesl").Items.Single();
// get descendants of type articlePost
var articles = start.Items.Descendants("ArticlePost");
}
@foreach(var c in articles)
{
<h2>@c.GetProperty("contentTitle")/h2>
}
nothing is returned now. The Errors are gone but the content although :). E.G. I have more than one "FolderArticles"
The Structure is the Following:
Content->Locations->Articles
and each Location has its own ArticleArea from Type FolderArticles where the ArticlePost is stored.
is working on a reply...