Copied to clipboard

Flag this post as spam?

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


  • umbraco lover 10 posts 94 karma points
    Jun 16, 2015 @ 16:53
    umbraco lover
    0

    Share content between sites

    Here's the scenario

    • SITE1
    • >EVENTS
    • >>EVENT1
    • >>EVENT2
    • >>EVENT3
    • SITE2

    I have a SITE1 with a list of events (DocType = 'Event')

    Events show OK using the configured template for SITE1 on url (http://site1/event1, http://site2/event2 .. )

    I want to be able to show same events on SITE2 using a different template (http://site2/event1 ..)

    How is this possible? I tried route hijacking without success.

  • Ste 14 posts 35 karma points
    Jun 18, 2015 @ 12:23
    Ste
    0

    Hi!

    If you are using a Razor page with access to the Umbraco API (such as UmbracoTemplatePage or PartialViewMacroPage), you could grab your events something like this:

    var events = Umbraco.TypedContentAtXPath("//Event")
        .Where(n => n.IsVisible())
        .ToList();
    

    This should give you a collection containing all Events across all sites. You need to change //Event to whatever your Doc Type is.

    Then you can render them using a Partial view or just use the data right away:

    @foreach(var e in events)
    {
        <p>e.Name</p>
    }
    

    Hope this helps!

  • Maff 141 posts 466 karma points
    Jun 18, 2015 @ 12:35
    Maff
    0

    Hi,

    Why not move the Events node to the root, and have it outside of both sites? Then you can do something like:

    var eventsFolder = @Umbraco.TypedContentAtRoot().Where(x => x.DocumentTypeAlias == "EventsFolder");
    var events = eventsFolder.Children();
    

    Bonus - this gives you re-usable code for both site 1 and site 2...

    Thanks,

    Maff

  • Maff 141 posts 466 karma points
    Jun 18, 2015 @ 12:36
    Maff
    0

    EDIT - that should be:

    var eventsFolder = @Umbraco.TypedContentAtRoot().FirstOrDefault(x => x.DocumentTypeAlias == "EventsFolder");
    
  • umbraco lover 10 posts 94 karma points
    Jun 18, 2015 @ 14:53
    umbraco lover
    0

    Thanks!

    I initially created the Events folder at the root but for some reason, the document didn't render. When I moved it under SITE1, it started working fine . using the right template.

    I want to move it back to the root .. but how do I get this to work

    url1 : http://site1/events/event1

    url2 : http://site2/events/event1

    where url1 and url2 will both use the same event data but a different template . ?

    I undersants the query part of it to retrieve the content, my problem is how can I use custom routing to determine a model and a template and render that .. !

    Thanks again!

  • Florian Mihalits 1 post 71 karma points
    Feb 05, 2016 @ 12:27
    Florian Mihalits
    0

    I would like to know that too.

    Did you ever figure out how to do this?

    Cheers

  • 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.

Please Sign in or register to post replies