I need to get the alias of the current template in v6.
In v4 the code should be something like: @(new Template(Model.Content.TemplateId).Alias Hovever, the Template used above is in cms.budinesslogic - that i don't want to use.
You need to use the Umbraco API if you want more information about the template"
And for razor the examine index maps that xml...
Maybe if you really don't want to hit the DB for this you will need to inject the templatealias into the examine lucene index and source from there with a custom searcher?
(Or another approach could be to hook into the application_starting event and enumerate the templates, so you create your own lookup for alias against id, once at app pool start into application state? session state? and then you can access from there later)
I need it to set a css-class in body to identify the template used. However i assume a approach with nodeTypeAlias and templateId is as good. Not as readable, but fair enough.
Get Alias of Current Template in v6 (razor)
Hi,
I need to get the alias of the current template in v6.
In v4 the code should be something like: @(new Template(Model.Content.TemplateId).Alias
Hovever, the Template used above is in cms.budinesslogic - that i don't want to use.
What would be the new approach?
... Currently using 6.1.2 (damn Edit won't work.)
Not sure you can get around this..
http://our.umbraco.org/forum/developers/api-questions/2832-getting-a-template-alias
as it states...
"The Umbraco XML cache does not contain the template alias (see http://our.umbraco.org/wiki/reference/umbraco-xml-format) it only contains the template ID.
You need to use the Umbraco API if you want more information about the template"
And for razor the examine index maps that xml...
Maybe if you really don't want to hit the DB for this you will need to inject the templatealias into the examine lucene index and source from there with a custom searcher?
http://our.umbraco.org/forum/using/ui-questions/37705-Examine-Indexer-setting-supportProtected?p=1#comment154709 might be a starting point for adding to the examine indexes.
(Or another approach could be to hook into the application_starting event and enumerate the templates, so you create your own lookup for alias against id, once at app pool start into application state? session state? and then you can access from there later)
Agreed. There's no point in calling the DB.
I need it to set a css-class in body to identify the template used. However i assume a approach with nodeTypeAlias and templateId is as good. Not as readable, but fair enough.
Thanks!
... also, i found: @Model.Content.GetTemplateAlias()
: )
... or Template.GetTemplate(doc.TemplateId) if i dont want to use the extension.
https://github.com/umbraco/Umbraco-CMS/search?q=getTemplateAlias&source=cc
GetTemplateAlias().. doing just what you are...
is working on a reply...