Why you are using a Razor Macro (DynamicNode) with Umbraco v7 (I would like to know so we can see if we need to adjust documentation etc)
In Umbraco v7, legacy Razor Macros (MacroScripts Folder) are for legacy support only. If you are using MVC templating then you can use Views and Partial Views, if you use MasterPage templates then you can use Macro Partial Views.
I've changed it from a Razor Macro (Macroscripts folder) to a partial view macro, but still cant get it to work, both variables are empty - So it still doesnt get the properties recursive?
@inherits Umbraco.Web.Macros.PartialViewMacroPage
@{
var parentalLink = CurrentPage.GetPropertyValue("linkToParental", true);
var externalLink = CurrentPage.GetPropertyValue("linkToExternal", true);
@Jeavon, the documentation says use CurrentPage in PartialViewMacros but with it being a dynamic type you get no intellisense in visual studio. Is traversing the content tree using Model.Content.Ancens... () just as acceptable?
@Nicky, to make this work change
var parentalLink = CurrentPage.GetPropertyValue("linkToParental", true);
to:
var parentalLink = Model.Content.GetPropertyValue("linkToParental", true);
@Dennis, yes you did indeed, just need to change Model to CurrentPage for MVC.
It think there is a issue somewhere (maybe documentation, maybe elsewhere), in that new people using v7 who have MVC templating as default are still creating Legacy Razor Macros (DynamicNode) when they need to be using View/Partial Views/Macro Partial Views.
Yeah, Dennis, if I were using DynamicNode, then you were also right :)
Another quick question - It looks like I cant use Model.NodeById() in the Partial View? When trying to render, the message is: Umbraco.Web.Models.RenderModel' does not contain a definition for 'NodeById'
var parentalLink = Model.Content.GetPropertyValue("linkToForaeldreForside", true);
Line 6: var externalLink = Model.Content.GetPropertyValue("linkToFriForMobberi", true);
Line 7: var parentalLinkNodeID = Model.NodeById(parentalLink);
@Paul, do you mean the documentation here which said "use Model.CurrentPage which exposes an instance of IPublishedContent or use CurrentPage", I've just fixed this to be "use Model.Content which exposes an instance of IPublishedContent or use CurrentPage" or somewhere else?
@Paul, great and thanks for spotting that. If you ever see any issues in the documentation, you can find the doc in the GitHub project, click edit, fix the issue and it will send us a pull request we can merge in.
get property recursive V.701
Im trying to get some properties recursive (as on http://umbraco.com/follow-us/blog-archive/2011/9/15/umbraco-razor-feature-walkthrough%E2%80%93part-6.aspx) , but I cant get it to work, im just getting an Error loading MacroEngine script...
@{
var parentalLink = Model.GetPropertyValue("linkToParental", true); //Contenpicker
var externalLink = Model.GetPropertyValue("linkToExternal", true); //Textfield
}
<div class="bottom-nav">
<div class="bottom-left">
<a class="btn parental" href="@parentalLink.Url"><span>For forældre</span></a>
</div>
<div class="bottom-right">
<a class="btn play" href="@externalLink"><span>Fri leg</span></a>
</div>
</div>
Hi Nicky,
What abou if you do like this:
I hope this will work for you. The documentation can be found here: http://our.umbraco.org/documentation/Reference/Querying/DynamicNode/Properties
/Dennis
Hi Nicky,
Why you are using a Razor Macro (DynamicNode) with Umbraco v7 (I would like to know so we can see if we need to adjust documentation etc)
In Umbraco v7, legacy Razor Macros (MacroScripts Folder) are for legacy support only. If you are using MVC templating then you can use Views and Partial Views, if you use MasterPage templates then you can use Macro Partial Views.
Jeavon
I've changed it from a Razor Macro (Macroscripts folder) to a partial view macro, but still cant get it to work, both variables are empty - So it still doesnt get the properties recursive?
@inherits Umbraco.Web.Macros.PartialViewMacroPage
@{
var parentalLink = CurrentPage.GetPropertyValue("linkToParental", true);
var externalLink = CurrentPage.GetPropertyValue("linkToExternal", true);
}
<div class="bottom-nav">
<div class="bottom-left">
<p>@parentalLink</p>
<p>@externalLink</p>
<a class="btn parental" href=""><span>For forældre</span></a>
</div>
<div class="bottom-right">
<a class="btn play" href=""><span>Fri leg</span></a>
</div>
</div>
@Jeavon, the documentation says use CurrentPage in PartialViewMacros but with it being a dynamic type you get no intellisense in visual studio. Is traversing the content tree using Model.Content.Ancens... () just as acceptable?
@Nicky, to make this work change
var parentalLink = CurrentPage.GetPropertyValue("linkToParental", true);
to:
var parentalLink = Model.Content.GetPropertyValue("linkToParental", true);
In the partial macroscript view, neither of these work:
CurrentPage.GetPropertyValue("linkToExternal", true);
or
Model.Content.GetPropertyValue("linkToExternal", true);
I tried both ways, and still returns nothing?
I've also tried creating a Partial View, and then output it with: @Html.Partial("BottomNav");
The code is almost the same, just inherits from another, but again, still returns nothing ? :( :
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@{
var externalLink = CurrentPage.GetProperyValue("linkToExternal");
}
<div class="bottom-nav">
<div class="bottom-left">
<p>@externalLink</p>
<a class="btn parental" href=""><span>For forældre</span></a>
</div>
<div class="bottom-right">
<a class="btn play" href=""><span>Fri leg</span></a>
</div>
</div>
The options are:
or
So I also have the right solution just for when you are using Razor Macro (DynamicNode) scripts :-)
/Dennis
@Dennis, yes you did indeed, just need to change Model to CurrentPage for MVC.
It think there is a issue somewhere (maybe documentation, maybe elsewhere), in that new people using v7 who have MVC templating as default are still creating Legacy Razor Macros (DynamicNode) when they need to be using View/Partial Views/Macro Partial Views.
Any thoughts?
Yeah, Dennis, if I were using DynamicNode, then you were also right :)
Another quick question - It looks like I cant use Model.NodeById() in the Partial View? When trying to render, the message is: Umbraco.Web.Models.RenderModel' does not contain a definition for 'NodeById'
var parentalLink = Model.Content.GetPropertyValue("linkToForaeldreForside", true); Line 6: var externalLink = Model.Content.GetPropertyValue("linkToFriForMobberi", true); Line 7: var parentalLinkNodeID = Model.NodeById(parentalLink);
@Paul, do you mean the documentation here which said
"use Model.CurrentPage which exposes an instance of IPublishedContent or use CurrentPage"
, I've just fixed this to be"use Model.Content which exposes an instance of IPublishedContent or use CurrentPage"
or somewhere else?Switch
for
or if using dynamics with CurrentPage, use:
Great, thx alot, you've been a great help :)
@Jeavon, yes that's right you got it ;-)
@Paul, great and thanks for spotting that. If you ever see any issues in the documentation, you can find the doc in the GitHub project, click edit, fix the issue and it will send us a pull request we can merge in.
is working on a reply...