Copied to clipboard

Flag this post as spam?

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


  • Raghav 34 posts 103 karma points
    Jan 19, 2015 @ 20:15
    Raghav
    0

    Resuable content with Umbraco 7

    HI,

    I have a requirement where in I want to reuse a content on different pages. 

    So basically my document type structure is OneColContentBlockFolder  having child node as OneColContentBlock. OneColContentBLock has title and desc as properties.

    The document type OneColContentBlockFolder   and HomePage are at the same level.

    I have created contents for OneColContentBlockFolder  under Content section . It has basically 4 OneColContentBlock Items inside it.

    How do I display it on the HomePage .OneColContentBlockFolder  is not the child node of Home page and this is because  the same content can be used on some other page.  I read this article http://our.umbraco.org/wiki/how-tos/creating-reusable-content but it is for older version of umbraco.

    Regards

    Raghav

     

     

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Jan 19, 2015 @ 21:18
    Dennis Aaen
    0

    Hi Raghav,

    I think that you should have a look on the bult-in property editor called multinode treepicker http://our.umbraco.org/documentation/using-umbraco/backoffice-overview/property-editors/Built-in-Property-Editors-v7/Multinode-Treepicker

    With this you can pick which content that you want to reuse on each page. So you add the property of the multinode treepicker on the document types for the pages where should be able to use the reuse content.

    You can filter on which document types that should be visible in the multinode treepicker, so you can limited for the user which elements that are available to pick in the content tree. Beware that the multinode treepicker data type is not there by default. But just go to the developer section, in the data types create a new data type, give the new data type a name, and then choose the multinodetreepicker as the property editor.

    Hope this helps, and make sense. If you have further questions don't hesitate to ask again.

    /Dennis

  • yogesh pathak 136 posts 221 karma points
    May 29, 2015 @ 12:36
    yogesh pathak
    0

    Hi Dennis,

    I need to use Multinode tree picker as i have to reuse chunks of content in diffrent pages, but the link you provided was not enough for me to understand that how can i render content i have picked at the design time by Mutinode Tree picker? , i have picked mutiple nodes of content but nothing renders on the preview page do i have to code in the tamplte to make it visible? if yes then can i you please provide a code example?

    Thanks

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    May 29, 2015 @ 14:11
    Dennis Aaen
    0

    Hi yogesh,

    You can add Razor code in three different ways. The first is directly in to temples. Others is by creating a partial view https://our.umbraco.org/documentation/Reference/Mvc/partial-views or partial view macro https://our.umbraco.org/documentation/Reference/Templating/Macros/Partial-View-Macros/. The partial view is create in the settings section, and the partial view macros are created in the developer section.

    You can use the same Razor code in both files, you just need to change where it inserts from if it´s is partial view or partial view macro. To be able to output data from the multiple node tree picker you will need these lines of code.

    For the dynamic Razor

    @{
        var bannerList = CurrentPage.banner.ToString().Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
        var bannerCollection = Umbraco.Content(bannerList);
        foreach (var item in bannerCollection)
        {
            <p>@item.Name</p>
        }
    }
    

    If you are using strongly typed Razor

    @{
        if (Model.Content.HasValue("banner"))
        {
            var bannerListValue = Model.Content.GetPropertyValue<string>("banner");
            var bannerList = bannerListValue.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse);
            var bannerCollection = Umbraco.TypedContent(bannerList).Where(x => x != null);
            foreach (var item in bannerCollection)
            {
                <p>@item.Name</p>
            }
        }
    }
    

    With this code rather if you are using dynamic Razor or strongly typed Razor your should now see the node names of the items that you have selected in the multiple node tree picker

    Remeber to change document type alias banner so it match your alias for the field with the multiple node tree picker.

    Hope this helps, and make sense

    /Dennis

  • yogesh pathak 136 posts 221 karma points
    May 29, 2015 @ 14:19
    yogesh pathak
    0

    Hi Dennis,

    i am able to list name of the content i have picked up ,but i have no idea how can i render content (i.e images ,text) of picked nodes here. can you show me an example of  rendering content of picked up nodes?

    thanks

    Regards

    yogesh pathak

  • Urvish 252 posts 776 karma points
    May 29, 2015 @ 14:21
    Urvish
    1

    Yogesh,

    I have given example of rendering content in below thread.

    https://our.umbraco.org/forum/umbraco-7/using-umbraco-7/64921-Reusing-a-Content?p=1#comment220388

    Regards,

    Urvish Mandaliya

  • yogesh pathak 136 posts 221 karma points
    May 29, 2015 @ 14:25
    yogesh pathak
    0

    Thanks Urvish/Dennis For the help , its working :) thanks a ton

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    May 29, 2015 @ 14:28
    Dennis Aaen
    0

    Hi yogesh,

    Now you are in a for each loop so current item is this there are picked in the multiple node tree picker. You can access custom properties like

    @item.propertyAlias 
    

    So if you have a property with alias of textString then you can access the data like

    @item.textSting.
    

    In case you have a picture you want to pull out please look at this documentation https://our.umbraco.org/documentation/Using-Umbraco/Backoffice-Overview/Property-Editors/Built-in-Property-Editors/Media-Picker please remember to choose the right Razor if you are using dynamics or strongly typed. But for the image to pull out it would be something like this.

    Dynamic

      if (item.HasValue("mainImage")){                                         
            var dynamicMediaItem = Umbraco.Media(CurrentPage.mainImage);
            <img src="@dynamicMediaItem.umbracoFile" alt="@dynamicMediaItem.Name"/>
        }
    

    Strongly typed.

    if(item.Content.HasValue("mainImage")){
            var mediaItem = Umbraco.TypedMedia(Model.Content.GetPropertyValue("mainImage")); 
            <img src="@mediaItem.GetPropertyValue("umbracoFile")" alt="@mediaItem.GetPropertyValue("Name")"/>    
        }   
    

    Remember again to change the mainImage property alias so it match yours

    Hope this helps and make sense.

    /Dennis

Please Sign in or register to post replies

Write your reply to:

Draft