I'm running a foreach loop, where I get all the nodes in a current level. In that foreach, I wan't to check wheather or not a node equals another node.
Here is the code:
var magazineLevel = Model.AncestorOrSelf(1).DescendantsOrSelf("Magazine").OrderBy("magazineDate desc, magazineDate");
var latestMagazine = magazineLevel.Take(1);
foreach (var page in magazineLevel)
{
if (page.IsEqual(latestMagazine))
{
//do something...
}else {
//do things to all the pages in magazineLevel...
}
}
I know that "latestMagazine" is the latest node, but I'm having trouble comparing the page node to the latest magazine node.
I don't get any errors in the debugger, and the script runs, but nothing happens during that statement.
Now, my question is as follows:
What is the correct way to compare and manipulate a node like this in umbraco, razor?
I hop you guys can help me, as you've done before. / Kind Regards.
Getting equal node during foreach
Hi guys.
I'm running a foreach loop, where I get all the nodes in a current level. In that foreach, I wan't to check wheather or not a node equals another node.
Here is the code:
I know that "latestMagazine" is the latest node, but I'm having trouble comparing the page node to the latest magazine node. I don't get any errors in the debugger, and the script runs, but nothing happens during that statement.
Now, my question is as follows:
What is the correct way to compare and manipulate a node like this in umbraco, razor?
I hop you guys can help me, as you've done before. / Kind Regards.
I don't know if its the most effiecent. but i usally just compare Url's
page.Url == latestMagazine.Url
or you could just compare Ids ?
page.Id == latestMagazine.Id
?Thank you for the reply Kevin. I think I might have had my head up my ass the last hour xD Of course it works :-). Thank you!
is working on a reply...