Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • James Inger 11 posts 102 karma points
    Oct 28, 2018 @ 20:20
    James Inger
    0

    Pass Value from Home page into partial view and render on every page

    Hi All,

    Fairly new to Umbraco, so be nice - I've looked around and cannot see an answer to my issue

    I have a Home Page and a second page, these are both under a Master template

    The second page is a child of the Home page.

    I have a partial view rendered in the Master view and then rendered on every page

    OK so the problem is that on the Partial Page it has some Values that im passing to it from the Home page. But when I render the second page the values do not come through. I understand that the content for these values are on the Home page, but they do not render on the second page.

    How can I pass the content from the Home Page to the second page and render it without creating the content on every single page.

    The partial views are my header and footers.

    Cheers

  • Nathan Woulfe 447 posts 1664 karma points MVP 5x hq c-trib
    Oct 29, 2018 @ 03:06
    Nathan Woulfe
    100

    Hi James

    You could try a recursive lookup on the property value - if you pass true as an optional parameter of GetPropertyValue() you can recurse up the content tree:

    content.GetPropertyValue('propertyAlias', true)

    Another option would be to move the property off the homepage and onto a config node, which you can then reference from anywhere in the site.

    Personally, I like using config nodes - has the added benefit of being able to provide permissions separate from the rest of the site content.

  • James Inger 11 posts 102 karma points
    Oct 29, 2018 @ 03:17
    James Inger
    0

    Hi Nathan,

    Thanks for that, I actually just figured that exact same answer out - took ages.

    For images

    @{
            var favIcon = Umbraco.Field("favIcon", recursive: true);
            if (favIcon != null)
            {
                var favIconimgurl = Umbraco.Media(favIcon.ToString()).Url;
                 <link href="@favIconimgurl" rel="shortcut icon" type="image/x-icon" />
            }
        }
    

    and then just for normal text.

    @Umbraco.Field("leftImageLink", recursive: true)
    

    Awesome - Thanks

Please Sign in or register to post replies

Write your reply to:

Draft