Hi all, I'm using a new installation of Umbraco 5 and trying to figure out whether I can make use of some reusable content, but using a macro to decide when its shown or not. I'll try to explain:
This is made visible to the user as a property on the homepage template/doctype. Once the user enters their data, I want ot be able to use this on child pages without having to renter the value per page. I'd like them to enter the value once on the homepage, then have the contents inherited by the child pages.
The child template I'd like to display this reusable content is called standard, which has the folloiwng macro partial:
When I then view a child page that is using the standard template/doctype, the html is rendered, but NOT the contents that the editor supplied on the home page (where it does correctly render).
I think what you're asking for is to retrieve the value "recursively", which Umbraco.Field should have a built-in option for. Try this:
@Umbraco.Field("heroText", recursive: true)
Note this will search all the way up the tree until it finds your property, so it's not necessarily always from the homepage - if you have "heroText" defined at a level between the current page and the homepage it will use the closest one.
Umbraco 5 and reusable content
Hi all, I'm using a new installation of Umbraco 5 and trying to figure out whether I can make use of some reusable content, but using a macro to decide when its shown or not. I'll try to explain:
I have a partial view (heroText.cshtml):
This is made visible to the user as a property on the homepage template/doctype. Once the user enters their data, I want ot be able to use this on child pages without having to renter the value per page. I'd like them to enter the value once on the homepage, then have the contents inherited by the child pages.
The child template I'd like to display this reusable content is called standard, which has the folloiwng macro partial:
The contents of this macro are:
When I then view a child page that is using the standard template/doctype, the html is rendered, but NOT the contents that the editor supplied on the home page (where it does correctly render).
Any ideas how I can achieve this?
Thanks
This seems to work, but doesn't feel quite right:
<div id="hero-text">
@Html.Raw(DynamicModel.AncestorsOrSelf.Last().heroText)
</div>
Hi Phil,
I think what you're asking for is to retrieve the value "recursively", which Umbraco.Field should have a built-in option for. Try this:
Note this will search all the way up the tree until it finds your property, so it's not necessarily always from the homepage - if you have "heroText" defined at a level between the current page and the homepage it will use the closest one.
More info on Umbraco.Field options
HTH,
Tom
Thanks Tom, that's great.
Do you know how I can use a partial inside a macro:
@Html.Partial("heroText")
Otherwise I have to copy the HTML contants of that partial into the macro which is duplicating code.
Thanks
Not off the top of my head, but try this:
(from http://issues.umbraco.org/issue/U5-261 )
-Tom
Worked a treat, thanks Tom
is working on a reply...