Copied to clipboard

Flag this post as spam?

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


  • Brad 94 posts 151 karma points
    Mar 26, 2013 @ 05:50
    Brad
    0

    What is wrong with this Razor?

    I have created a new .cshtml file in my Developer/Scripting Files folder. 

    The content of this file thus far is this.

     @inherits umbraco.MacroEngines.DynamicNodeContext


    @if(umbraco.library.IsLoggedOn())
    {
          <div id="ShowSideNavMemberOptions">
    }else{
        <div id="HideSideNavMemberOptions">
    }

        <div id="SideNav">
            <div id="Content">
                Here is some content
            </div>
        </div>   
       
    </div>

    As you can see I want a different DIV output depending if the user is logged in or not.

    However I cannot save this .cshtml file as I get this error.

    Error occured
    The if block is missing a closing "}" character. Make sure you have a matching "}"
    character for all the "{" characters within this block, and that none of the "}" characters are being interpreted as markup.

    Missing what? I just can't see what the problem is here.

  • Fuji Kusaka 2203 posts 4220 karma points
    Mar 26, 2013 @ 06:05
    Fuji Kusaka
    0

    Hi Brad,

    No you are not missing a "}" here!! its only the way you are calling you script

    @if(umbraco.library.IsLoggedOn())
    {
          <div id="ShowSideNavMemberOptions">
                    <div id="SideNav">
                        <div id="Content">
                            Here is some content
                        </div>
        </div>       
              </div>
    }else{
        <div id="HideSideNavMemberOptions">
            </div>
    }

    But in any case i dont think you really need the else statement here if you are planning to hide content

     

    //fuji

     

  • Brad 94 posts 151 karma points
    Mar 26, 2013 @ 06:29
    Brad
    0

    That's not what I have planned.. I need to show the SideNav content regardless, but I need a different div with different styles around it depending on the users logged in state.

    What I need to end up with is this... 


    <div id="ShowSideNavMemberOptions">
        <div id="SideNav">
           
    <div id="Content">
               
    Hereis some content
           
    </div>
        </
    div>    
    </div>

    Or this..

    <div id="HideSideNavMemberOptions">
        <div id="SideNav">
           
    <div id="Content">
               
    Hereis some content
           
    </div>
        </
    div>    
    </div>

    So the structure of what I have is correct, it is just a syntax issue.

    "Hide" in this case will just mean that certain items are rendered as disabled and have a different style applied, but that is not the issue at hand here.

    What did you mean by "the way you are calling your script"? This is a pretty standard .cshtml file that is put into a Macro and is loaded into a page template.

     

  • Fuji Kusaka 2203 posts 4220 karma points
    Mar 26, 2013 @ 07:29
    Fuji Kusaka
    0

    Hi Brad,

    What i meant was there was a missing closing div inside your @if.

    Did you get it working though ?

  • Carsten Fallesen 35 posts 154 karma points
    Mar 26, 2013 @ 08:34
    Carsten Fallesen
    100

    Hi Brad,

    You could do something like this:

    @{
        var navId = umbraco.library.IsLoggedOn() ? "ShowSideNavMemberOptions" : "HideSideNavMemberOptions";
    }
    
    <div id="@navId">
        <div id="SideNav">
            <div id="Content">
                Hereis some content
            </div>
        </div>
    </div> 
    
    Hope this helps.

    /Carsten

  • Brad 94 posts 151 karma points
    Mar 26, 2013 @ 23:05
    Brad
    0

    Carsten

    Elegant solution. Thanks for that.

    Just curious, any idea why my code did not work?

Please Sign in or register to post replies

Write your reply to:

Draft