Copied to clipboard

Flag this post as spam?

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


  • Ivan 165 posts 543 karma points
    Dec 12, 2012 @ 17:20
    Ivan
    0

    Placeholders in .css file.

    Hi guys.

    How do I dynamically assign values to .css file based on values in Document Type.

    So for example, if my document type contains Width and Height fields, and I set them as 10px and 20px accordingly, then I would like my .css looked as:

    .image {

    width: 10px;

    height: 20px;

    }

    Any thoughts?

    PS.

    There's strict requirement not to use inline styling and HTML Style tag.

  • Paul Wright (suedeapple) 277 posts 704 karma points
    Dec 13, 2012 @ 00:54
    Paul Wright (suedeapple)
    0

    Various ways of doing this - One is use a self referencing altTemplate.  

    In yoursection, you will need to add something like this

     <link href="<umbraco:Item field="pageID" runat="server" xslt="umbraco.library:NiceUrl({0})" />?alttemplate=css" type="text/css" rel="stylesheet" />

     

    Then, create a new alttemplate called css.master, and create an inline Macro, and put something like this into it..
    <%@ Master Language="C#" MasterPageFile="~/umbraco/masterpages/default.master" AutoEventWireup="true"  %>
    
    <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolderDefault" runat="server">
    
    <umbraco:Macro runat="server" language="cshtml">
    @{
     Context.Response.ContentType = "text/css";
    }
    
    .image
    {
       width:@Model.imageWidth
       height:@Model.imageHeight
    }
    </umbraco:Macro>
    
    
    </asp:Content> 
  • Ivan 165 posts 543 karma points
    Dec 13, 2012 @ 07:54
    Ivan
    0

    Very nice, Paul.

    Your solution works perfectly!

  • Ivan 165 posts 543 karma points
    Dec 17, 2012 @ 13:56
    Ivan
    0

    Hi Paul.

    Is there a way to disable escaping for inline macro?

    For example, when I have this CSS rule in the template:

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

    @{

     Context.Response.ContentType = "text/css";

    }

    .body

    {

       font-family: "myriad-pro-condenced", sans-serif;

    }

    </umbraco:Macro>

    It will be automatically converted to the escaped symbols:

    .body {

       font-family: &quot;myriad-pro-condenced&quot;, sans-serif;

    }

  • Paul Wright (suedeapple) 277 posts 704 karma points
    Dec 17, 2012 @ 14:15
    Paul Wright (suedeapple)
    0

    Think you may need to use...

    @Html.Raw(Model.myFont)

     

  • Ivan 165 posts 543 karma points
    Dec 17, 2012 @ 14:36
    Ivan
    0

    Perfect!

    It works, thanks.

Please Sign in or register to post replies

Write your reply to:

Draft