Copied to clipboard

Flag this post as spam?

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


  • Anders Brohus 194 posts 475 karma points
    Jul 28, 2015 @ 11:46
    Anders Brohus
    0

    Check if page has field and if it has then check if its not empty

    Hi!.. :)

    I'm currently doing some work on an Umbraco 4 installation, where i only have access to the "Settings" section.

    What i want to do is very simple but i just don't know how since it's Umbraco 4 and i'm not that good at Umbraco 4 xD

    But i would like it to check if the page has field, and if it has then it should check that its not empty.

    In Umbraco 7 i think i would do something like this

    @if(CurrentPage.HasProperty("TestProperty"))
    {
        if(CurrentPage.GetProperty("TestProperty"))
        {
            something awesome code
        }
    }
    

    Can you guys help me? :)

    It's v4.9.0 :)

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Jul 28, 2015 @ 11:51
    Dennis Aaen
    0

    Hi Anders,

    If I remember right then in Umbraco 4.9.0 you only have the option to use the old DynamicNode Razor. And then the syntax should be like this:

    @if(Model.HasProperty("TestProperty"))
    {
        if(Model.HasValue("TestProperty"))
        {
            something awesome code
        }
    }
    

    Hope this helps,

    /Dennis

  • Anders Brohus 194 posts 475 karma points
    Jul 29, 2015 @ 07:12
    Anders Brohus
    0

    But can i use that inside the template?

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Jul 29, 2015 @ 07:27
    Dennis Aaen
    0

    Hi Anders,

    You can use this Razor code snippets in your template like your normally do.

    /Dennis

  • Anders Brohus 194 posts 475 karma points
    Jul 29, 2015 @ 08:40
    Anders Brohus
    0

    Hmmm i just tried and it printed out in the html :/

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Jul 29, 2015 @ 08:58
    Dennis Aaen
    0

    Hi Anders,

    What if you do something like this. I have totally forgot that in 4.9.0 you need to wrap the inline Razor code in a macro.

    <umbraco:Macro runat="server" language="cshtml">                                                        
         @if(Model.HasProperty("TestProperty"))
            {
              if(Model.HasValue("TestProperty"))
                {
                   something awesome code
              }
          }              
    </umbraco:Macro>
    

    Hope this helps,

    /Dennis

  • Anders Brohus 194 posts 475 karma points
    Jul 29, 2015 @ 11:08
    Anders Brohus
    0

    Nope still not working, keep the "500 - Internal server error." :(

Please Sign in or register to post replies

Write your reply to:

Draft