Copied to clipboard

Flag this post as spam?

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


  • blackhawk 313 posts 1368 karma points
    Nov 30, 2017 @ 03:26
    blackhawk
    0

    Content Node data to Partial View

    Is it possible to call content out of a specific content node and load it into a partial view?

    My goal to have an editor to create content from a content node, which then I can make global by referencing it into a partial view.

    If this is possible is there an online resource in achieving this?

    Many thanks!

  • Ben Palmer 176 posts 842 karma points c-trib
    Nov 30, 2017 @ 08:26
    Ben Palmer
    0

    Hi blackhawk,

    I'm not sure there's quite enough detail here to figure out what you're doing, any chance you could you elaborate on the end goal here?

  • blackhawk 313 posts 1368 karma points
    Nov 30, 2017 @ 10:35
    blackhawk
    0

    Sure, I want editors to be able to modify the footer content of the entire web site (which is the same on all pages) without leaving the Content section of BackOffice.

  • Ben Palmer 176 posts 842 karma points c-trib
    Nov 30, 2017 @ 10:55
    Ben Palmer
    100

    Thanks blackhawk,

    So if I'm understanding this correctly, we would usually do this within a Settings tab setup on the homepage. So, on your homepage document type, you might create a Footer Text field, for example. Then all you need to do is get the homepage and the property from their. An easy way to get the homepage on a single-site installation can be:

    IPublishedContent homepage = Umbraco.TypedContentAtRoot().First();
    

    You'd probably want to null check it when making use of it too:

    @if (homepage != null)
    {
        // code
    }
    

    Hope I understood correctly and that helps.

  • blackhawk 313 posts 1368 karma points
    Dec 04, 2017 @ 16:35
    blackhawk
    0

    Close...I want to do something like this on my master template...

       @*place the following condition on my master template*@
    
        IPublishedContent homepageItem = //get property alias "myText" that was created on the home document type.
    
        @if (homepageItem != null)
        {
            <p>@homepageItem</p>
        }
    

    That's what I am shooting for, but do not know how to write with IPublishedContent.

  • Dan Diplo 1554 posts 6205 karma points MVP 5x c-trib
    Nov 30, 2017 @ 13:17
    Dan Diplo
    2

    An alternative way to get the homepage content (which also works when you have multiple home pages is):

    var homePage = Model.Content.AncestorOrSelf(1);
    

    or in more recent versions of Umbraco, simply:

    var homePage = Model.Content.Site();
    
  • blackhawk 313 posts 1368 karma points
    Dec 04, 2017 @ 15:09
    blackhawk
    0

    Thanks Dan! and taking it just one step further, what if I simply wanted to reference a property alias from the home page (i.e. a rich text editor that has a property alias called my text). How can I call just that, onto other sibling templates?

    I apologize, this should of been my original question.

  • Dan Diplo 1554 posts 6205 karma points MVP 5x c-trib
    Dec 04, 2017 @ 16:38
    Dan Diplo
    1

    So, once you have your homePage variable populated then you can access properties as you would Model.Content (it's all IPublishedContent) ie.

    var homePage = Model.Content.Site();
    
    var myText = homePage.GetPropertyValue<IHtmlString>("myText");
    

    If your property was a string you would use:

      string myText = homePage.GetPropertyValue<string>("myText");
    
  • blackhawk 313 posts 1368 karma points
    Dec 04, 2017 @ 16:41
    blackhawk
    0

    Bingo! Thank you. That is exactly what I was looking for!

Please Sign in or register to post replies

Write your reply to:

Draft