This is a very simple requirement but I can't seem to find a simple solution anywhere.
I want the user to be able to enter text that will appear on all pages. If I add properties to my master page, the user must enter text for each child page that is created. I want them to be able to enter the text once only, as it is the same text that appears on each page.
What is the simplest structure I can use to achieve this?
If I put the property on my master page (which is inherited by all other pages), the property will appear on the content nodes of all pages. The user will then have to enter the same text multiple times, which is not what I want.
I usually create a doctype ad hoc for my root node, so I can add the properties reserved for it:
Master doctype
Home doctype (here the property)
Doctype 2
etc
If you don't want to change doctype to your root node you can add the property to your master doctype and then use the package "backoffice tweaking"
http://our.umbraco.org/projects/collaboration/backoffice-tweaking
to hide the property from all other doctypes but the root node doctype.
My structure is not hierarchical in this way. Rather than create doctype1, 2 etc as children of my master doctype I am using document type compositions to specify the relationship. One thing I have tried is to create a common data doctype at the same level as everything else, like so:-
Master doctype
Doctype 1
Doctype 2
CommonData doctype
Doctypes 1 and 2 have master doctype checked in the document type compositions section. I'm not sure how to bring the common data document type into the relationship....
As such Jim it doesn't matter if it happens to be on every item of content.
The recursive lookup will look up the content tree till it finds an item with a value.
So if it is filled in on your home node and blank on any created under it, it will look up the tree till it happens to find it.
-Home - Has property value
--Child 1 - Blank property value
--Child 2 - Blank property value
In this case, Child 1 and Child 2 would display the value from the home node.
However if it was given a value on Child 2 it will then display what has been entered on Child 2, and the children under this will have that value (provided they too are left blank).
I tend to have a Home document type, so it makes it easier to set this at this level as it only appears on the one node, so the user can't accidentally overwrite it a a lower level.
Perhaps another option might be to use a dictionary item instead, depending on what sort of text you are envisaging.
Anthony - I may be able to restructure my site to use your solution but as things stand all pages are at the same level (root). Although they all inherit from the same master page doctype (via document type compositions), the structure is currently flat.
This means that each page is a sibling rather than a child and I'm guessing that if the user enters the common data on one sibling this data would not be available to the other siblings via the recursive lookup mechanism (would it?)
That's correct Jim, the recursive property only works in an up direction and not sideways.
In that case René's last suggestion is probably going to be the best answer for you in this situation. Having a separate item and getting the information directly from that.
write once, use many
Hi
This is a very simple requirement but I can't seem to find a simple solution anywhere.
I want the user to be able to enter text that will appear on all pages. If I add properties to my master page, the user must enter text for each child page that is created. I want them to be able to enter the text once only, as it is the same text that appears on each page.
What is the simplest structure I can use to achieve this?
Thanks
Jim
Hi Jim, you can put a property on the root node of your application and then use
where the second parameter is "isRecursive?"
Hope this help
Stefano
Hi Stefano
Thanks very much for your reply.
I'm not sure I understand what you mean by 'put a property on the root node of your application'. Could you please explain a little more?
Thanks
Jim
Hi Jim,
you will have to create a property on the root-level documentType (or where you want it to inherit from).
In your view, you then use the recursive option in the GetProperty method:
The propertyAlias string will be your propertyalias on the root documenttype and the boolean true, makes the call recursive.
/René
Hi Jim,
I think René explained better what I was suggesting you.
Is that the solution?
BR
Stefano
Thanks both.
If I put the property on my master page (which is inherited by all other pages), the property will appear on the content nodes of all pages. The user will then have to enter the same text multiple times, which is not what I want.
I think I'm still missing something.....
Jim
Hi Jim, you are correct.
If the doctype strucuture of your website is:
Master doctype (here the property)
so yes, the property will appear on every node.
I usually create a doctype ad hoc for my root node, so I can add the properties reserved for it:
Master doctype
If you don't want to change doctype to your root node you can add the property to your master doctype and then use the package "backoffice tweaking" http://our.umbraco.org/projects/collaboration/backoffice-tweaking to hide the property from all other doctypes but the root node doctype.
BR Stefano
Hi Stefano
My structure is not hierarchical in this way. Rather than create doctype1, 2 etc as children of my master doctype I am using document type compositions to specify the relationship. One thing I have tried is to create a common data doctype at the same level as everything else, like so:-
Doctypes 1 and 2 have master doctype checked in the document type compositions section. I'm not sure how to bring the common data document type into the relationship....
Jim
As such Jim it doesn't matter if it happens to be on every item of content.
The recursive lookup will look up the content tree till it finds an item with a value.
So if it is filled in on your home node and blank on any created under it, it will look up the tree till it happens to find it.
-Home - Has property value
--Child 1 - Blank property value
--Child 2 - Blank property value
In this case, Child 1 and Child 2 would display the value from the home node.
However if it was given a value on Child 2 it will then display what has been entered on Child 2, and the children under this will have that value (provided they too are left blank).
I tend to have a Home document type, so it makes it easier to set this at this level as it only appears on the one node, so the user can't accidentally overwrite it a a lower level.
Perhaps another option might be to use a dictionary item instead, depending on what sort of text you are envisaging.
Hi Jim,
in that case you can always get data from a node by loading this node in your razorview like:
Where 1234 is the id of the CommonData doctype.
/René
Thanks for your replies, Rene and Anthony.
Anthony - I may be able to restructure my site to use your solution but as things stand all pages are at the same level (root). Although they all inherit from the same master page doctype (via document type compositions), the structure is currently flat.
This means that each page is a sibling rather than a child and I'm guessing that if the user enters the common data on one sibling this data would not be available to the other siblings via the recursive lookup mechanism (would it?)
Jim
That's correct Jim, the recursive property only works in an up direction and not sideways.
In that case René's last suggestion is probably going to be the best answer for you in this situation. Having a separate item and getting the information directly from that.
If its just a simple text string why not use a dictionary item?
Hi Anthony
I decided to try your solution first.
Unfortunately, when I place the following code snippet in my master page template:-
@(Model.GetProperty("propertyAlias", true))
I get the following error message:-
I have also tried putting the code snippet in a partial view but the result is the same.
Up until this point I was using the field inclusion snippet
@Umbraco.Field("propertyAlias")
Is there a recursive variant of this I should be using?
Jim
I'm using this:
Seems to work for me.
Although as Mike said, if it's a simple text string a Dictionary Item might be easier.
Excellent - that works for me too!
I've made a note of all the other suggestions for further experimentation.
Thanks to all those who responded.
Jim
is working on a reply...