Copied to clipboard

Flag this post as spam?

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


  • Daniel Jensen 28 posts 159 karma points
    Jan 21, 2016 @ 12:24
    Daniel Jensen
    0

    @Umbraco.Field("pagename") not working? but @CurrentPage.Name is? Shouldn't both work?

    Hi, I have a template, where i want to print out the generic property with the name of the node. If i use the GUI in backoffice to do this, i get this razor code:

    @Umbraco.Field("pagename")
    

    It does however not do anything. Not printing out the name of the page nor giving an exception. However, if i use this:

    @CurrentPage.Name
    

    then it works perfectly.

    Does anyone have an explaination on this?

    My template is quite simple, it looks like this:

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @{
        Layout = "MasterPage.cshtml";
    }
    <div class="col-sm-12">
        <div class="row">
            <div class="col-sm-12">
                <h2>@Umbraco.Field("pagename")</h2> //does nothing
                @Model.Content.Name //does nothing
                @CurrentPage.Name //works perfectly
            </div>
            <div class="col-sm-12">
                @Umbraco.Field("pageContent")
            </div>
        </div>
    </div>
    

    Thanks in advance, Daniel

  • Dennis Aaen 4490 posts 18155 karma points admin hq c-trib
    Jan 21, 2016 @ 12:45
    Dennis Aaen
    100

    Hi Daniel and welcome to our :-).

    To get the page name of the page, using @Umbraco.Field, you will need to use this syntax.

    @Umbraco.Field("pageName")
    

    Hope this helps,

    /Dennis

  • Daniel Jensen 28 posts 159 karma points
    Jan 21, 2016 @ 12:58
    Daniel Jensen
    0

    Alright, It works flawlessly now. Perhaps it was some cache or something that was preventing it from showing, when i was testing it.

    Thanks, I'm super excited with starting on Umbraco. :)

  • Dennis Aaen 4490 posts 18155 karma points admin hq c-trib
    Jan 21, 2016 @ 13:03
    Dennis Aaen
    1

    Great that is works for you now.

    Please notice that the uppercased N is in pageName :-) The aliases of the field are generated after the camel casing.

    which mean every time you do a space in the name of your property, then it will get a uppercase letter.

    Hope this helps,

    /Dennis

Please Sign in or register to post replies

Write your reply to:

Draft