I have a feature in my Umbraco site where sidebar content can be defined once, and it will persist through all child pages until it is overridden. This works well enough by just using the following in my template:
However what I want to do now is allow a per-page "hide sidebar" flag that can remove the sidebar at any point in the tree. So I added a true/false page field alias "hideSidebar" and changed by template to use the following:
@{
if (!String.IsNullOrEmpty(Model.hideSidebar.ToString()))
{
if (!Model.hideSidebar)
{
<aside class="sidebar">
@Model._sidebarContent
</aside>
}
}
}
Unfortunately it doesn't seem to be working. I've debugged the conditional logic so I know that isn't the problem, and the <aside> is printed, just with nothing in it. When I switch the @Model._sidebarContent to just @Model.sidebarContent, I can get the content for the current page as expected.
So the problem is with the recursion. Clearly I'm doing something wrong syntactically.
I appreciate the reply, but when I put that code in my template, the result is showing markup in my rendered page instead of the final desired output.
Also, I need this to stay recursive so that the content can be set at one level and persist to child nodes, but be overriden or hidden at each node if necessary (see above).
Quick check... which version of Umbraco are you using? I *think* the underscore prefix was only added in v4.7.1 (but not sure if it's v4.7.1.1 though?)
Getting page fields recursively in razor macro
Hi everyone,
I have a feature in my Umbraco site where sidebar content can be defined once, and it will persist through all child pages until it is overridden. This works well enough by just using the following in my template:
However what I want to do now is allow a per-page "hide sidebar" flag that can remove the sidebar at any point in the tree. So I added a true/false page field alias "hideSidebar" and changed by template to use the following:
Then in my .cshtml file I have the following:
Unfortunately it doesn't seem to be working. I've debugged the conditional logic so I know that isn't the problem, and the <aside> is printed, just with nothing in it. When I switch the @Model._sidebarContent to just @Model.sidebarContent, I can get the content for the current page as expected.
So the problem is with the recursion. Clearly I'm doing something wrong syntactically.
Basically what I want is this:
in the middle of a macro.
For reference, I was reading through this topic but I couldn't quite seem to get it working.
Looks like I got it working:
However I could still use some guidance/feedback on what I could do better.
Well I was wrong. The @Model expression I used will render richtext content, but it will not render macros that have been inserted in the editor.
What I really need is to duplicate the
functionality in my macro.
Or better yet, is there way to include conditional logic in my template around the <umbraco:Item> call?
Hi Alex,
I asked the same question... Recursive fields using Razor macro
Take a read over the replies, there are quite a few ways to do it.
Cheers, Lee.
Ah, sorry, just noticed that you'd already seen my post about it.
Wouldn't my example work for you?
Lee,
I appreciate the reply, but when I put that code in my template, the result is showing markup in my rendered page instead of the final desired output.
Also, I need this to stay recursive so that the content can be set at one level and persist to child nodes, but be overriden or hidden at each node if necessary (see above).
Quick check... which version of Umbraco are you using? I *think* the underscore prefix was only added in v4.7.1 (but not sure if it's v4.7.1.1 though?)
Yeah, I'm in 4.7.0 (Assembly version: 1.0.4090.38017)
is working on a reply...