Inherit property value from parent node ("master")
Hi! I have a master page. My master.cshtml page has my header, @RenderBody(), and my footer.
My footer has some text, which I get from a Vorto property using @Model.Content.GetVortoValue("contactText").
Now: This footer is used throughout the site and is never changed, which is why I put it in my master template page. However, when I go to a subpage (like /news/), the @Model has changed and no longer has the Vorto property values that the master template did.
It does make sense why it doesn't have that. I guess you could call this unneeded and bad behavior (that all my child pages inherit some property from the footer), but I'm not sure what else I can do.
Should I do something like a Partial View for my footer perhaps? What other options do I have?
It will be nice to do Partial for the footer, then you will be able to use CachedPartial, that is much faster than render footer on each page with each request.
Instead of using Current page model like @Model.Content.GetVortoValue("contactText"), try to use rootNode, like this:
var rootNode = Umbraco.AssignedContentItem.Site();
rootNode.GetVortoValue("contactText");
With this code you will use the same root node on all pages. Hope it will help you.
How much faster is a CachedPartial? My footer has two pictures in it (SVGs though). What about a CachedPartial for the header as well? One image (same image as in footer). Are we talking crazy fast compared to or?
CachedPartial will not affect images, it's a question of rendering, when it cached, this part of page renders from memory, and it takes 0,000001 seconds :)
Inherit property value from parent node ("master")
Hi! I have a master page. My master.cshtml page has my header,
@RenderBody()
, and my footer.My footer has some text, which I get from a Vorto property using
@Model.Content.GetVortoValue("contactText")
.Now: This footer is used throughout the site and is never changed, which is why I put it in my master template page. However, when I go to a subpage (like
/news/
), the@Model
has changed and no longer has the Vorto property values that the master template did.It does make sense why it doesn't have that. I guess you could call this unneeded and bad behavior (that all my child pages inherit some property from the footer), but I'm not sure what else I can do.
Should I do something like a Partial View for my footer perhaps? What other options do I have?
Thanks!
Hi Morten
Instead of using Current page model like @Model.Content.GetVortoValue("contactText"), try to use rootNode, like this:
var rootNode = Umbraco.AssignedContentItem.Site(); rootNode.GetVortoValue("contactText");
With this code you will use the same root node on all pages. Hope it will help you.
Thanks,
Alex
Hi Alex!
That's very cool. It worked perfectly, thanks!
How much faster is a CachedPartial? My footer has two pictures in it (SVGs though). What about a CachedPartial for the header as well? One image (same image as in footer). Are we talking crazy fast compared to or?
Thanks!
Morten,
CachedPartial will not affect images, it's a question of rendering, when it cached, this part of page renders from memory, and it takes 0,000001 seconds :)
Thanks
Very cool! I'll definitely look into using this tomorrow. Thanks!
You are welcome, ask if you have some questions!
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.