the different id selectors (#page2, #page3, etc ...) are then added to the body-tag of the page:
<body id="page3">
My question is, how can I make this dynamic in an Umbraco Masterpage? My first thought is to create a documenttype property, say 'layoutId' and then add this to the Masterpage template:
How about if you create a custom DataType DropDown List then add the values in this case the ids (page2, page3, etc... ) , since you have a the same value for page 2 you could add the following
Not sure if this will solve your issue thought, i did that for a project of mine there the client could have the possibility to change the background color of this website.
That's indeed a better solution than having a doctype property of datatype Text. Still cumbersome a bit is that the end user has to define which style to use. The ultimate solution of course would be that the Masterpage "just knows" wich layout style to use, based for instance on the Template used.
Thanks for the advice. I don't know if there is an Itemfield for a Template. If there is, that would solve the problem of dynamically loading the correct id selector for the body-tag.
I'm not sure eithet, but if does not exists, it definitely exists in the razor dynamic node model (see cheat sheet), so worse case you might use inline razor I guess.
there is a @template field item, but this returns the id of a template, not it's Name. I'm now looking into the Razor Cheatsheet. It says that the DynamicNode has a .Template property, but I'm not quiet sure how to access that property
anyone accessed the Template name in a Razor file?
'umbraco.cms.businesslogic.template.Template' does not contain a definition for 'GetProperty' and no extension method 'GetProperty' accepting a first argument of type 'umbraco.cms.businesslogic.template.Template' could be found (are you missing a using directive or an assembly reference?)
Mmmh too bad. I don't have access to code here but there must certainly be a GetValue method or something like this... Or could it be that you just have a ".Text" property. Pff, I don't remember... Hope somebody else does.
However, I didn't find a way to inject a dynamic value in the GetTemplate(template id) method, so I think in the end Fuji's solution is the most practical, so I will mark that solution as the solving one.
However, I hope in the future it will be more easy to dynamically inject a template name in the body tag of a Master page.
make id attribute dynamic in body tag
Hi,
I have a style sheet that has some different style definitions for the layout of several different pages:
/* ============================= page2 ===========================*/
#page2 .col-2 .col-1 {width:230px;}
#page2 .col-2 .col-2 {width:230px;}
/* ============================= page3 ===========================*/
#page3 .col-2 .col-1 {width:280px;}
#page3 .col-2 .col-2 {width:219px;}
/* ============================= page5 ===========================*/
#page5 .col-2 .col-1 {width:260px;}
#page5 .col-2 .col-2 {width:239px;}
the different id selectors (#page2, #page3, etc ...) are then added to the body-tag of the page:
<body id="page3">
My question is, how can I make this dynamic in an Umbraco Masterpage? My first thought is to create a documenttype property, say 'layoutId' and then add this to the Masterpage template:
<body id="<umbraco:Item field='layoutId' runat='server' />">
Hi Anthony,
How about if you create a custom DataType DropDown List then add the values in this case the ids (page2, page3, etc... ) , since you have a the same value for page 2 you could add the following
Not sure if this will solve your issue thought, i did that for a project of mine there the client could have the possibility to change the background color of this website.
//fuji
Hi Fuji,
That's indeed a better solution than having a doctype property of datatype Text. Still cumbersome a bit is that the end user has to define which style to use. The ultimate solution of course would be that the Masterpage "just knows" wich layout style to use, based for instance on the Template used.
thanks for the advice,
Anthony
Hi Anthony,
If you want to auto-set the style based on the template, maybe you can do something like this:
and then rename your stylsheet "#pageX" classes by ".TemplateName"? I'm not sure about the name of the field property returning the template...
In that case, if the user changes the template, the style will change automatically.
Cheers,
Michael.
Hi Michael,
Thanks for the advice. I don't know if there is an Itemfield for a Template. If there is, that would solve the problem of dynamically loading the correct id selector for the body-tag.
greetings,
Anthony
Hi Anthony,
I'm not sure eithet, but if does not exists, it definitely exists in the razor dynamic node model (see cheat sheet), so worse case you might use inline razor I guess.
Cheers,
Michael.
there is a @template field item, but this returns the id of a template, not it's Name. I'm now looking into the Razor Cheatsheet. It says that the DynamicNode has a .Template property, but I'm not quiet sure how to access that property
anyone accessed the Template name in a Razor file?
Thanks for your help,
Anthony
I found a part of the solution here:
http://our.umbraco.org/forum/developers/xslt/1764-testing-against-active-template-name-%5Bsolved%5D
but I use this method in my template:
<%= umbraco.cms.businesslogic.template.Template.GetTemplate(1055) %>
I get this result:
<body id="{Id:1055, Text:Homepage, ParentId: -1}">
While I just want the name of the template (eg. Homepage) so the result is this:
<body id="Homepage">
I know I'm close, I just need this little push from the Umbraco Communit
Thanks,
Anthony
Maybe call the GetProperty method:
<%= umbraco.cms.businesslogic.template.Template.GetTemplate(1055).GetProperty("Text") %>
Cheers,
Michael.
Hi Michael,
tried it but this doesn't work, I get an YSOD:
'umbraco.cms.businesslogic.template.Template' does not contain a definition for 'GetProperty' and no extension method 'GetProperty' accepting a first argument of type 'umbraco.cms.businesslogic.template.Template' could be found (are you missing a using directive or an assembly reference?)
Mmmh too bad. I don't have access to code here but there must certainly be a GetValue method or something like this... Or could it be that you just have a ".Text" property. Pff, I don't remember... Hope somebody else does.
jep, found it:
<%= umbraco.cms.businesslogic.template.Template.GetTemplate(1055).Text %>
Thanks a lot Michael
OK Great :-)
to recap, what I did to add the name of an Umbraco template dynamically in the body tag of my Masterpage, I did the following:
1. In the body tag of my masterpage I defined a contentplaceholder like this:
<body id="<asp:ContentPlaceHolder Id="ph_body" runat="server" />">
2. In the Content Template, for instance the Homepage template, I added a content region like this:
<asp:Content ContentPlaceHolderId="ph_body" runat="server">
<%= umbraco.cms.businesslogic.template.Template.GetTemplate(1055).Text %>
</asp:Content>
The result in the rendered page is this:
So I just need to find a way to tidy up the output a little and clean up the spaces
I was close to a solution putting this in the body tag of my Master page:
<body id="<%= umbraco.cms.businesslogic.template.Template.GetTemplate(1055).Text %>" />
However, I didn't find a way to inject a dynamic value in the GetTemplate(template id) method, so I think in the end Fuji's solution is the most practical, so I will mark that solution as the solving one.
However, I hope in the future it will be more easy to dynamically inject a template name in the body tag of a Master page.
greetings,
Anthony
is working on a reply...