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 All,
So it's fixed, but its a really stupid fix I found by accident, and as best I know it shouldn't work. And this took hour to find.
@inherits Umbraco.Web.Macros.PartialViewMacroPage @{ if (!String.IsNullOrEmpty(Model.MacroParameters["newsRoot"].ToString())) { dynamic node = @Umbraco.Content(Model.MacroParameters["newsRoot"]).Children; <div></div> foreach (var newss in node.Take(1).OrderBy("createDate desc")) { <a href="@Umbraco.Content(newss.Id).Url" alt="@newss.pageTitle"> <div class="col2NewsA"> <h3>@newss.pageTitle</h3> <span><p>@newss.teaserText</p></span> <img src="@newss.GetCropUrl("newsImage", "newsTile")" alt="@newss.pageTitle image" /> </div> </a> } } }
OK, so this is for "Partial View Marco Files" (not a partial view).
You see the line 5 down, "div /div".
It won't work without that. I have had problems with foreach before inside if's but not like this.
As far as I am concerned if the "div /div" is in there the "foreach" should start with an @, right?? Put the @ in and it's broken again.
What is happening, are there some mad special rules for foreach?
Thanks
Stephen
Purely a guess but try removing the @ symbol on this line.
@
dynamic node = @Umbraco.Content(Model.MacroParameters["newsRoot"]).Children;
You're still in a code block there so you shouldn't need to use it.
Thanks James, that was what was causing it. That's the problem with coding late at night, you miss the obvious.
<div></div> foreach (var newss in node.Take(1).OrderBy("createDate desc"))
You are closing the div tags before the foreach loop, so you're still in the code block.
If you had done something like:
<div> foreach (var newss in node.Take(1).OrderBy("createDate desc")) { <a href="@Umbraco.Content(newss.Id).Url" alt="@newss.pageTitle"> <div class="col2NewsA"> <h3>@newss.pageTitle</h3> <span><p>@newss.teaserText</p></span> <img src="@newss.GetCropUrl("newsImage", "newsTile")" alt="@newss.pageTitle image" /> </div> </a> } </div>
Where you write code inside the div tags, then you'd have to use "@" infront of the Foreach loop.
James is also right, the "@" is not needed on:
dynamic node = Umbraco.Content(Model.MacroParameters["newsRoot"]).Children;
Since you are inside the code block
This should be the code without the empty div tags:
@inherits Umbraco.Web.Macros.PartialViewMacroPage @{ if (!String.IsNullOrEmpty(Model.MacroParameters["newsRoot"].ToString())) { dynamic node = Umbraco.Content(Model.MacroParameters["newsRoot"]).Children; foreach (var newss in node.Take(1).OrderBy("createDate desc")) { <a href="@Umbraco.Content(newss.Id).Url" alt="@newss.pageTitle"> <div class="col2NewsA"> <h3>@newss.pageTitle</h3> <span><p>@newss.teaserText</p></span> <img src="@newss.GetCropUrl("newsImage", "newsTile")" alt="@newss.pageTitle image" /> </div> </a> } } }
Thanks for the info, yes James was right, that was the problem.
Great stuff. Glad I could help!
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
OK so this is weird, can someone explain
Hi All,
So it's fixed, but its a really stupid fix I found by accident, and as best I know it shouldn't work. And this took hour to find.
OK, so this is for "Partial View Marco Files" (not a partial view).
You see the line 5 down, "div /div".
It won't work without that. I have had problems with foreach before inside if's but not like this.
As far as I am concerned if the "div /div" is in there the "foreach" should start with an @, right?? Put the @ in and it's broken again.
What is happening, are there some mad special rules for foreach?
Thanks
Stephen
Purely a guess but try removing the
@
symbol on this line.You're still in a code block there so you shouldn't need to use it.
Thanks James, that was what was causing it. That's the problem with coding late at night, you miss the obvious.
You are closing the div tags before the foreach loop, so you're still in the code block.
If you had done something like:
Where you write code inside the div tags, then you'd have to use "@" infront of the Foreach loop.
James is also right, the "@" is not needed on:
Since you are inside the code block
This should be the code without the empty div tags:
Thanks for the info, yes James was right, that was the problem.
Great stuff. Glad I could help!
is working on a reply...