Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Anders Brohäll 295 posts 561 karma points c-trib
    Jul 04, 2013 @ 16:59
    Anders Brohäll
    0

    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?

  • Anders Brohäll 295 posts 561 karma points c-trib
    Jul 04, 2013 @ 17:02
    Anders Brohäll
    0

    ... Currently using 6.1.2 (damn Edit won't work.)

  • Mike Chambers 621 posts 1203 karma points c-trib
    Jul 05, 2013 @ 11:04
    Mike Chambers
    100

    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)

  • Anders Brohäll 295 posts 561 karma points c-trib
    Jul 05, 2013 @ 11:32
    Anders Brohäll
    0

    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!

  • Anders Brohäll 295 posts 561 karma points c-trib
    Jul 05, 2013 @ 11:37
    Anders Brohäll
    0

    ... also, i found: @Model.Content.GetTemplateAlias()
    : ) 

  • Anders Brohäll 295 posts 561 karma points c-trib
    Jul 05, 2013 @ 11:39
    Anders Brohäll
    0

    ... or Template.GetTemplate(doc.TemplateId) if i dont want to use the extension.

  • Mike Chambers 621 posts 1203 karma points c-trib
    Jul 05, 2013 @ 12:37
    Mike Chambers
    0

    https://github.com/umbraco/Umbraco-CMS/search?q=getTemplateAlias&source=cc

    GetTemplateAlias().. doing just what you are...

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies