Its confusing. When i make the Template under an other Master Template the Umbraco.Field works. But when i make the Template to a Master Template i don't have access to the Documenttype anymore.
Are you trying to use your master "template" to hold content that you want to reuse on multiple pages across your site?
If so I think you've misunderstood what a master template does. What you're looking for can be done easily however. I'll explain how if you can confirm I've understood you correctly?
yes, thats what i use my mastertemplate for. In Master Template i have my Navigation and Footer.. and at "RenderBody" i Render my Content, that is different on every page.
OK - I can see where you're confused... Basically you can use master templates / doc types to do what you're doing for the common content but you also need to access data from a different content node to the one that's being requested to get the header and footer content.
Here's a quick overview of the terminology so there's no confusion!
Master template - a template that other templates use that contains common header / footer / html skeleton / Umbraco field requests.
Master Doc type - a doc type that all doc types below it will inherit the doc type fields (data / content "fields"). This paradigm has recently (mostly) been replaced with Doc Type compositions where you build up a doctype from other ones rather than inherit.
Content - content nodes in the tree - from a template (either within the template itself or a master) you can "traverse" up the tree to get content either from the content node requested or one of it's parents... e.g.
Home
- News
- - August 2016
- - - some Article
If page "Some Article" was requested Umbraco will use the doc type and template for this content node but you might also use content from the news home or August 2016 or even the home node if the same value is not set on "Some Article" .. to do this you'd request the property value recursively (so it traverses up the tree).
// get the value from the current content node or travel up it's parents
@Umbraco.Field("text", true)
Using the above method you could therefore put your header and footer information in the Home node and always request it recursively. I don't like doing this - I think what you're trying to do (which is how I build sites) is to have a common container of this content outside of the content tree - I tend to call this "Site Settings" rather than Master to avoid confusion with the doc type / template stuff.
You basically do what you've done, create a doc type called Site settings and create the content fields for your header / footer content (no need for master doc types!). Then within your page templates (e.g. for the news article, homepage and news container in the example above) you just need to "Get" a reference to the site settings node as Umbraco will only contain the content from the current node (or allow you to recursively work up the parents as above).
To do this at the top of your template you need something like:
int siteSettingsNodeId = 1234; // check the properties tab of your site settings node get this - it will be different for your site!
var siteSettingsNode = Umbraco.TypedContent(siteSettingsNodeId);
Now you can use the siteSettingsNode where need common content as well as content from the CurrentPage - as this is strongly typed node you access the fields like this:
(note I suggest you follow the Typed examples). Remember how we used Umbraco.TypedContent - well notice how these are TypedMedia.. hopefully the mist will begin to clear!
Master Documenttype
Hello our.umbraco
I created a new Documenttype called "Master" and tried to get the "Umbraco.Fields" at my Master Template but it didn't work.
(for example Navigation Points)
How can i link my Master Documenttype to my Master Template that i can use Umbraco.Field("test") at my Master Template?
Hi Hubert,
Did you select "Master Template" as template of Master page?
How did you try to get "Umbraco.Fields" ? Can you share the code?
Thanks,
Alex
am i doing something wrong?
ty
And how did you try to render the page ? your code please?
is renders but i doesnt render the:
its empty...
Only this field?
Try this line of code -
doesn't work.
Its confusing. When i make the Template under an other Master Template the Umbraco.Field works. But when i make the Template to a Master Template i don't have access to the Documenttype anymore.
Please help.
no not only this field. It doens't render all fields.
Hi Hubert,
Are you trying to use your master "template" to hold content that you want to reuse on multiple pages across your site?
If so I think you've misunderstood what a master template does. What you're looking for can be done easily however. I'll explain how if you can confirm I've understood you correctly?
Steve
yes, thats what i use my mastertemplate for. In Master Template i have my Navigation and Footer.. and at "RenderBody" i Render my Content, that is different on every page.
Am i doing it wrong?
OK - I can see where you're confused... Basically you can use master templates / doc types to do what you're doing for the common content but you also need to access data from a different content node to the one that's being requested to get the header and footer content.
Here's a quick overview of the terminology so there's no confusion!
Master template - a template that other templates use that contains common header / footer / html skeleton / Umbraco field requests.
Master Doc type - a doc type that all doc types below it will inherit the doc type fields (data / content "fields"). This paradigm has recently (mostly) been replaced with Doc Type compositions where you build up a doctype from other ones rather than inherit.
Content - content nodes in the tree - from a template (either within the template itself or a master) you can "traverse" up the tree to get content either from the content node requested or one of it's parents... e.g.
If page "Some Article" was requested Umbraco will use the doc type and template for this content node but you might also use content from the news home or August 2016 or even the home node if the same value is not set on "Some Article" .. to do this you'd request the property value recursively (so it traverses up the tree).
Using the above method you could therefore put your header and footer information in the Home node and always request it recursively. I don't like doing this - I think what you're trying to do (which is how I build sites) is to have a common container of this content outside of the content tree - I tend to call this "Site Settings" rather than Master to avoid confusion with the doc type / template stuff.
You basically do what you've done, create a doc type called Site settings and create the content fields for your header / footer content (no need for master doc types!). Then within your page templates (e.g. for the news article, homepage and news container in the example above) you just need to "Get" a reference to the site settings node as Umbraco will only contain the content from the current node (or allow you to recursively work up the parents as above).
To do this at the top of your template you need something like:
Now you can use the siteSettingsNode where need common content as well as content from the CurrentPage - as this is strongly typed node you access the fields like this:
or for rich text:
Hopefully this will put you on the right path.
Steve
Oh god now i get it... Thank you so much!
Textboxes are
what are images? mediapaths?
can u help me? ;)
if have for example an media picker and i want the path of the image who is selected?
Now you have the above the documentation should make more sense... so where you see Model.Content. replace with siteSettingsNode
How to use a Media Picker
(note I suggest you follow the Typed examples). Remember how we used Umbraco.TypedContent - well notice how these are TypedMedia.. hopefully the mist will begin to clear!
Steve
Hubert,
if you want to display the image from your media picker then you could do something like:
/Michaël
thank you both! :) its now clear to me. cu
is working on a reply...