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.
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.
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?
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.
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?
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
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
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
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
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
If you are using strongly typed Razor
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
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
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
Thanks Urvish/Dennis For the help , its working :) thanks a ton
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
So if you have a property with alias of textString then you can access the data like
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
Strongly typed.
Remember again to change the mainImage property alias so it match yours
Hope this helps and make sense.
/Dennis
is working on a reply...