I am following a tutorial (posted here) which explains a way to create footer navigation. I'm setting a NaviHide Property within the pages I don't want to show, and also using 'umbracoRedirect' to push me to the pages I do. My Footer Nav macro also has a "Source" parameter that I am passing along as a Content Picker when inserting it in the template. The redirect portion is fine, but I am getting stymied when trying to complete the last portion, which is to create a macro which shows certain pages. Here is the macro in question (created as a Partial View Macro):
@inherits Umbraco.Web.Macros.PartialViewMacroPage
var parent = @Model.NodeById(Parameter.Source);
if (parent != null) { <ul> @foreach (var item in parent.Children.Where("Visible")) { <li> <a href="@item.Url">@item.Name</a> </li> } </ul> }
However, when running the page, I get an unhelpful "Error Loading Partial View script (file: ~/Views/MacroPartials/FooterNav2.cshtml)" message.
I've tried recreating it as a regular Partial View in the Settings Menu, which at least gives me a compilation error message. The error says "CS1061: 'Umbraco.Web.Models.PartialViewMacroModel' does not contain a definition for 'NodeById' and no extension method 'NodeById' accepting a first argument of type 'Umbraco.Web.Models.PartialViewMacroModel' could be found (are you missing a using directive or an assembly reference?)"
The offending portion of my code is the "var parent = @Model.NodeById(Parameter.Source);" line. Is there something else I should be using besides "NodeById"? Is it even possible for me to grab a specific page and say I want all of its children so that I can display them as a menu?
On a related note: I am continually frustrated by not knowing what properties, methods, and data I can access from a Partial View. Is there any sort of reference that shows these items? Is there anything I can add to my URLs to debug things? I'm swimming blind out here, even after having gone through the Implementor video tutorials.
That tutorial is slightly out of date and is for the now legacy "Razor Macro" where as you are using the current "Partial View Macro". It is easily adapted though:
@inherits Umbraco.Web.Macros.PartialViewMacroPage
var parent = Umbraco.Content(Model.MacroParameters["Source"].ToString());
if (parent != null) {
<ul>
@foreach (var item in parent.Children.Where("Visible")) {
<li>
<a href="@item.Url">@item.Name</a>
</li>
}
</ul>
}
Thanks for the reply, Jeavon! That's helpful to know there's a new syntax. Is the UmbracoHelper page a good reference for finding methods to query data out of Umbraco, or is there a better page?
I had to make one more adjustment to the code: My syntax for defining a variable was undefined. I had to wrap my variable in brackets with an @ symbol: @{ var x = something }.
However, I'm still having an issue where my "if" statement is getting rendered as HTML rather than Razor code. Any idea why?
NodeById - Umbraco doesn't like it
Hello everyone,
I am following a tutorial (posted here) which explains a way to create footer navigation. I'm setting a NaviHide Property within the pages I don't want to show, and also using 'umbracoRedirect' to push me to the pages I do. My Footer Nav macro also has a "Source" parameter that I am passing along as a Content Picker when inserting it in the template. The redirect portion is fine, but I am getting stymied when trying to complete the last portion, which is to create a macro which shows certain pages. Here is the macro in question (created as a Partial View Macro):
However, when running the page, I get an unhelpful "Error Loading Partial View script (file: ~/Views/MacroPartials/FooterNav2.cshtml)" message.
I've tried recreating it as a regular Partial View in the Settings Menu, which at least gives me a compilation error message. The error says "CS1061: 'Umbraco.Web.Models.PartialViewMacroModel' does not contain a definition for 'NodeById' and no extension method 'NodeById' accepting a first argument of type 'Umbraco.Web.Models.PartialViewMacroModel' could be found (are you missing a using directive or an assembly reference?)"
The offending portion of my code is the "var parent = @Model.NodeById(Parameter.Source);" line. Is there something else I should be using besides "NodeById"? Is it even possible for me to grab a specific page and say I want all of its children so that I can display them as a menu?
On a related note: I am continually frustrated by not knowing what properties, methods, and data I can access from a Partial View. Is there any sort of reference that shows these items? Is there anything I can add to my URLs to debug things? I'm swimming blind out here, even after having gone through the Implementor video tutorials.
Thanks and bless ya...
Hi Chris,
That tutorial is slightly out of date and is for the now legacy "Razor Macro" where as you are using the current "Partial View Macro". It is easily adapted though:
Jeavon
Sorry, I was missing the brackets:
Thanks for the reply, Jeavon! That's helpful to know there's a new syntax. Is the UmbracoHelper page a good reference for finding methods to query data out of Umbraco, or is there a better page?
I had to make one more adjustment to the code: My syntax for defining a variable was undefined. I had to wrap my variable in brackets with an @ symbol: @{ var x = something }.
However, I'm still having an issue where my "if" statement is getting rendered as HTML rather than Razor code. Any idea why?
Yes, the UmbracoHelper documentation and the general MVC documentation There are also a lot of helpful snippets for the property editors here
Hopefully you have seen my second post above with the braces?
Ah, that fixes it - I didn't notice where you started the code with an "@{". Sorry about that!
And thanks for the references, I'll make sure to bookmark them.
Hi Chris,
Great! could you please mark the correct solution above by using the green tick?
Thanks,
Jeavon
is working on a reply...