Copied to clipboard

Flag this post as spam?

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


  • Luke 4 posts 24 karma points
    Jul 18, 2014 @ 02:15
    Luke
    0

    Access media globally

    Hi,

    I'm having trouble accessing the same media folder for every page.

    Ihave a setup as follows:

    Document types

    Master
    -> Home
    -> About
    -> etc

    Templates

    Layout
    ->Home Page
    -> Text Page
    -> etc

    Under the media tab i have a folder called 'Banners' which has a number of images in it.

    My Layout contains something along the lines of;

    @{ Html.RenderPartial("umbTopNavigation"); }
    @{ Html.RenderPartial("umbBanner"); }
    @RenderBody()

    Essentially, i need the umbBanner partial view to access the same media items for every page.

    Any help would be greatly appreciated. If you need any more info, please let me know.

    Thanks,

    Luke.

     

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Jul 18, 2014 @ 08:10
    Dennis Aaen
    0

    Hi Luke,

    I assume that you are picking the folder with image on the front page documenttype and then want the same image on all other pages.

    If so you need to call the partial view recursive, so it goes up in the content tree until it found the field where it´s not empty.

    You can call a property rerecursive like this for strongly typed razor:

    @Model.Content("_propertyAlias")
    

    or if you are using dynamic razor

    @CurrentPage("_propertyAlias")
    

    The documentation can be found here: http://our.umbraco.org/documentation/Reference/Querying/DynamicNode/Properties

    If I remember correct you can also call the partial view recursive, by simply do this:

    @{ Html.RenderPartial("umbBanner", true); }
    

    http://our.umbraco.org/documentation/Reference/Mvc/views#RenderingafieldwithUmbracoHelper

    Hope this helps,

    /Dennis

  • Luke 4 posts 24 karma points
    Jul 18, 2014 @ 08:38
    Luke
    0

    Could have sworn i deleted this topic, as i came to the solution myself.
    Thanks for the help anyway Dennis. Not sure i understand fully what you mean however.

    For anyone who comes into a similar problem, or if I'm doing it completely wrong, here's what i did;

    Document Types
    Master
    -> Home
    -> Text Page
    -> Media Folder (this has a multiple media picker property called media)

    Content
    Home (Home document type)
    -> About (Text page document type)
    -> Banners (Media folder document type)

    and my partial view;

    @inherits UmbracoTemplatePage

    @{
    var homePage = CurrentPage.AncestorsOrSelf(1).First();
    var bannerPage = homePage.umbMediaFolder.Where("Name == @0", "Banners").First();
    }

    <!-- Boarder -->
    <div>
    <img src="~/images/BannerBoarder.png" />
    </div>
    <!-- /Boarder -->

    <!-- slider -->
    <div id="slider">
    <div class="callbacks_container">
    <ul class="rslides pic_slider">
    @foreach (var id in bannerPage.Media.Split(','))
    {
    var banner = Umbraco.Media(int.Parse(id));
    <text>
    <li><img src="@banner.Url" alt="@banner.Name" /></li>
    </text>
    }
    </ul>
    </div>
    </div>
    <!-- slider close -->
Please Sign in or register to post replies

Write your reply to:

Draft