Copied to clipboard

Flag this post as spam?

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


  • Ronnie Overby 14 posts 37 karma points
    Apr 02, 2011 @ 22:29
    Ronnie Overby
    0

    Problem with simple inline razor

    All I want to do is this inline razor:

    <umbraco:Macro runat="server" language="cshtml">

    @if(Model.noSidebar)

    {

    <style>

    //SOME CSS

    </style>

    }

    </umbraco:Macro>

    What am I doing wrong?

  • Niels Hartvig 1951 posts 2391 karma points c-trib
    Apr 02, 2011 @ 22:44
    Niels Hartvig
    0

    > What am I doing wrong?

    Could you let us know what the problem is? It's a little hard to tell from your post which makes it difficult to help :)

  • Ronnie Overby 14 posts 37 karma points
    Apr 03, 2011 @ 00:14
    Ronnie Overby
    0

    The legend, himself!

    Right, sorry about not including the error. I was thinking my syntax was way off or something, but I guess not.

     

  • Toni Becker 146 posts 425 karma points
    Apr 03, 2011 @ 11:03
    Toni Becker
    0

    Try this out our use your code but you should add the @inherits to make it work your razor code.
    Test it and than give me an answer.

    <umbraco:Macro  runat="server" language="cshtml">
    @inherits umbraco.MacroEngines.DynamicNodeContext
    @{
      if (Model.HasProperty("noSidebar")) {
     
        @foreach (var sideBar in @Model.Children) {
          <style type="text/css">
    YOUR CSS
    </style>

    }
      }
    }

    </umbraco:Macro>

  • Sebastiaan Janssen 5058 posts 15520 karma points MVP admin hq
    Apr 04, 2011 @ 07:22
    Sebastiaan Janssen
    0

    Could you tell us what version of Umbraco you're using and if it's an upgrade from an older version (and if it is an upgrade, did you add the extra keys to web.config and umbracosettings.config)?

    As Toni says, you might want to check if the property exists, but you don't need the inherits.

    <umbraco:Macro  runat="server" language="cshtml">
    @if (Model.HasProperty("NoSidebar") && Model.NoSidebar) {
       <style type="text/css">
        YOUR CSS
       </style>
    }
    </umbraco:Macro>

    Also, make sure that the casing of the property name of "NoSidebar" is correct (except for the first letter, it can be either upper or lower case.

  • Toni Becker 146 posts 425 karma points
    Apr 04, 2011 @ 07:29
    Toni Becker
    0

    Good morning Sebastiaan :) hope you've spent a nice weekend. And here it comes :)
    Can you have a look at my former post "Coding Logic..." please.

    I need some help for a customer project :) Thanks a lot

  • Ronnie Overby 14 posts 37 karma points
    Apr 04, 2011 @ 12:45
    Ronnie Overby
    0

    I'm using a fresh install of 4.7

     

    The casing in the razor matches the alias on the document type.

     

    All of this is happening on my development machine with WebMatrix.

  • Jonas Eriksson 930 posts 1825 karma points
    Apr 04, 2011 @ 15:04
    Jonas Eriksson
    0

    Happens to me to. Seems to be something with <style> and inline macro scripts. http://umbraco.codeplex.com/workitem/30225 other tags I tested works fine (<p> for example>

    Workaround : move the script to a macro instead and add the macro to your template.

  • Alex 78 posts 136 karma points
    Apr 04, 2011 @ 15:05
    Alex
    0

    Hmm, I get the same error when I try to include a <script> tag inside the Macro. Not sure why, but you can always do something like this to get around it.

    <style type="text/css">
    <umbraco:Macro  runat="server" language="cshtml">
    @if(Model.noSideBar)
    {
       @:{color:red;}
       @:{color:blue;}
    }
    </umbraco:Macro>
    </style>

     

  • Toni Becker 146 posts 425 karma points
    Apr 04, 2011 @ 15:29
    Toni Becker
    0

    Hy alex hope you've spent a nice weekend, could you look at my topic please and see if you have some kind of solution or maybe a way to solve this problem.

    Here comes the link. http://our.umbraco.org/forum/developers/razor/19068-Coding-Logic-for-Razor-DynamicNode-and-Properties-ideas-needed

    Thanks for everything

Please Sign in or register to post replies

Write your reply to:

Draft