Copied to clipboard

Flag this post as spam?

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


  • Tom Cowling 144 posts 342 karma points
    Mar 21, 2014 @ 14:45
    Tom Cowling
    0

    Combining razor and html

    Hey,

    Quick question - I want to pull in a different style sheet depending on the selection of a drop menu. The problem I am having is that I can pull in the field, but how do I stictch it into the html code in the header?

    Here's what I have so far:

    <umbraco:Macro  runat="server" language="cshtml">
    @inherits umbraco.MacroEngines.DynamicNodeContext
    @{
    if (Model.HasValue("colourScheme"))
    {
    <link rel="stylesheet" type="text/css" href="@Model.colourScheme.css" />
    }
    }
    </umbraco:Macro>

    That will break the page because .css is not a procedure(not sure of correct terminology?) of Model so therefore break. It works fine with a space in (as expected).

    For example:

    @Model.colourScheme .css

    How can I stitch @Model.colourScheme and the .css together?

     

    I've tried + and && but can't seem to work it out - any help would be much appreciated!

     

    Thanks,

    Tom

  • Dennis Aaen 4457 posts 17970 karma points admin hq c-trib
    Mar 21, 2014 @ 14:50
    Dennis Aaen
    2

    Hi Tom,

    You could try something like this:

    @Model.colourScheme@Html.Raw(".css");

    Hope this helps,

    /Dennis

  • Tom Cowling 144 posts 342 karma points
    Mar 21, 2014 @ 14:55
    Tom Cowling
    0

            Works perfectly - thanks a lot Dennis!

    <umbraco:Macro  runat="server" language="cshtml">
            @inherits umbraco.MacroEngines.DynamicNodeContext
            @{
            if (Model.HasValue("colourScheme"))
                {                 
                <link rel="stylesheet" type="text/css" href="@[email protected](".css")" />
                }
            }
            </umbraco:Macro>
  • Jan Skovgaard 11258 posts 23500 karma points MVP 7x admin c-trib
    Mar 21, 2014 @ 14:55
    Jan Skovgaard
    0

    Hi Tom

    Have you tried writing it this way...

    <link rel="stylesheet" type="text/css" href="(@Model.colourScheme +".css")" />

    Hope this helps.

    /Jan

  • Jan Skovgaard 11258 posts 23500 karma points MVP 7x admin c-trib
    Mar 21, 2014 @ 14:56
    Jan Skovgaard
    0

    Once again late to the party - Glad you got it solved :) #h5yr Dennis!

    /Jan

  • Tom Cowling 144 posts 342 karma points
    Mar 21, 2014 @ 14:59
    Tom Cowling
    0

    Ninja'd at the last minute! :)

     

    Thanks for the alternative response though

  • 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