Copied to clipboard

Flag this post as spam?

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


  • Stephan Andersen 2 posts 32 karma points
    Jun 04, 2015 @ 12:59
    Stephan Andersen
    0

    How can I share content between pages?

    I'm a Umbraco newbie and I'm looking for a way to share notifications between two pages.

    I have this structure:

    Content
    > Home (Will display notifications)
    > > Support (Will display notifications)
    > > About
    > >  ... etc
    > Notifications
    > > Notification1
    > > Notification2

    I was hoping I could just add something like a ContentQuery property to the Home and Support DocumentTypes, where I could get published children of Notifications. I see there is a Content Picker (Multiple), but I dont want to manually set which ones to display.

    I dont want to put the notifications inside the Home content tree either, it is not the same people handling the content and those who need to put out alerts.

    If it isnt a native way of doing it, can someone tell me how I can access this data directly in a template/view?

    I'm using Umbraco 7.2.5 and am quite familiar with Razor and MVC.

  • James Jackson-South 489 posts 1747 karma points c-trib
    Jun 04, 2015 @ 14:01
    James Jackson-South
    100

    Hi Stephen,

    This sounds like something I would use Route Hijacking to do.

    Within your ActionResult you can use the UmbracoHelper property to query the document tree and grab whatever bits you want for your view model.

    Let me know if you need more information.

    Cheers

    James

  • Stephan Andersen 2 posts 32 karma points
    Jun 04, 2015 @ 15:56
    Stephan Andersen
    0

    Thanks James!

    It's working now :)

    Stephan

  • James Jackson-South 489 posts 1747 karma points c-trib
    Jun 04, 2015 @ 16:18
    James Jackson-South
    0

    Excellent! Glad I could help :)

  • James Jackson-South 489 posts 1747 karma points c-trib
    Jun 04, 2015 @ 20:46
    James Jackson-South
    0

    Hi Stephan,

    Got this within an email but it's not on the forum...

    Thanks James!

    It's working now. I do have a follow up question, though:

    I changed @inherits Umbraco.Web.Mvc.UmbracoTemplatePage to @inherits Umbraco.Web.Mvc.UmbracoViewPage and lost @CurrentPage. Is there a cleaner way to get to the Document Type properties than this.Content.Properties.FirstOrDefault(x => x.PropertyTypeAlias == "myPropertyAlias");?

    Stephan

    Funny you should ask that. I've been working on something recently with a few other guys that allows you to pass strong typed models to your views. There's an article about it here.

    Cheers

    James

Please Sign in or register to post replies

Write your reply to:

Draft