Copied to clipboard

Flag this post as spam?

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


  • Anders Schmidt 76 posts 207 karma points
    Nov 04, 2014 @ 11:04
    Anders Schmidt
    0

    Check if Umbraco.Field exist

    I am retriving umbraco field like this:

    Umbraco.Field(string fildalias)

    How to check if field exist/is created ?

    if (Umbraco.Field("itemsPerSite") != null) is not enough

    Thansk

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Nov 04, 2014 @ 11:11
    Dennis Aaen
    0

    Hi Anders,

    You can do it like this:

    if (CurrentPage.HasValue("itemsPerSite")){ 
       @Umbraco.Field("itemsPerSite")
    }

    The HasValue check if the field has a value of the current page that you are viewing in the browser.

    Hope this helps,

    /Dennis

  • jivan thapa 194 posts 681 karma points
    Nov 04, 2014 @ 11:55
    jivan thapa
    0
    if(CurrentPage.HasProperty("itemsPerSite"))
        {        
        }
    
  • Anders Schmidt 76 posts 207 karma points
    Nov 04, 2014 @ 12:12
    Anders Schmidt
    0

    Thanks. for anwsers. Sorry forgot to say i am not able in usinge currentpage or model.

    Is there another solution?

     

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Nov 04, 2014 @ 12:47
    Dennis Aaen
    0

    Hi Anders,

    The @Umbraco.Field(string field) returns the value of that field from the Current Page. http://our.umbraco.org/documentation/Reference/Querying/UmbracoHelper/#Field%28stringfield%29 If you want to access a property on the parent or so, then you should have a look at the axis: http://our.umbraco.org/documentation/reference/templating/macros/razor/using-razor-axes

    Or have a look on this cheat sheets, there a both dynamic razor and strongly typed razor, I know it says for V6, but you should be good with it in version 7 also. http://our.umbraco.org/projects/developer-tools/umbraco-v6-mvc-razor-cheatsheets

    If you can tell more a about where the user should type in the value, of the field and your content structure, maybe we can help you closer to solve your issue.

    Hope this helps,

    /Dennis

  • jivan thapa 194 posts 681 karma points
    Nov 04, 2014 @ 13:01
    jivan thapa
    0

    Try this one, Remember to inherit the template from UmbracoTemplatePage

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    
    @{
        if (Model.Content.HasProperty("itemsPerSite"))
        {
    
        }
    
    }
    
  • 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