Copied to clipboard

Flag this post as spam?

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


  • Heather Floyd 610 posts 1032 karma points MVP 6x c-trib
    Nov 23, 2010 @ 22:52
    Heather Floyd
    0

    How can I inject a css STYLE section into page HEAD in a macro?

    Hi, I am working on an XSLT which dynamically creates some css rules (using width & height params passed in), and of course I can just output the  <style type="text/css"> ...</style> right in the middle of the page body (aka where the macro is placed) but this does cause some problems with XHTML validation, so I was wondering if there is a way to inject this chunk of HTML into the page <head> tag instead?

    I saw umbraco.library:RegisterStyleSheetFile(), but I don't have an external file to link to, so that won't work.

    I also saw umbraco.library:RegisterClientScriptBlock(), but haven't been able to find any documentation to determine if this would be usable for my purposes...

    My initial tests haven't worked out. This is the XSLT:

    <xsl:variable name="HeadCSS" >
      <![CDATA[<style type="text/css">]]>
      #s3slider
      {
        width:<xsl:value-of select="$RotatorNode/data[@alias='JCWidth']"/>px;
        height:<xsl:value-of select="$RotatorNode/data[@alias='JCHeight']"/>px;
      }
      #s3sliderContent
      {
        width:<xsl:value-of select="$RotatorNode/data[@alias='JCWidth']"/>px;
      }
      .s3sliderImage span {
        background-color:<xsl:value-of select="$RotatorNode/data[@alias='JCColor']"/>;
      }
      .s3sliderImage span.ctop,.s3sliderImage span.cbottom
      {
        width:<xsl:value-of select="($RotatorNode/data[@alias='JCWidth'])-26"/>px;  
      }
      .s3sliderImage span.cleft,.s3sliderImage span.cright,.s3sliderImage span.ccenter
      {
        width: <xsl:value-of select="($RotatorNode/data[@alias='JCCaptionWidth'])"/>;
        height:<xsl:value-of select="($RotatorNode/data[@alias='JCHeight'])-20"/>px;
      }
      .s3sliderImage span.ccenter
      {
        width: <xsl:value-of select="($RotatorNode/data[@alias='JCWidth'] div 2)"/>px;
        height:<xsl:value-of select="($RotatorNode/data[@alias='JCHeight'] div 3)"/>px;  
      }
      <![CDATA[</style>]]>
      </xsl:variable>
      <xsl:value-of select="umbraco.library:RegisterClientScriptBlock('jCarouselCSS', $HeadCSS, 0)"/>

    But when I check the rendered page, this isn't added to the <head> section (or anywhere else).

    Any ideas?

    Thanks!

    Heather

  • Sean Mooney 131 posts 158 karma points c-trib
    Nov 23, 2010 @ 23:06
    Sean Mooney
    0

    Do you have runat="server" on the head tag?

    <head runat="server">
  • Heather Floyd 610 posts 1032 karma points MVP 6x c-trib
    Nov 23, 2010 @ 23:19
    Heather Floyd
    0

    Yes.

  • Sean Mooney 131 posts 158 karma points c-trib
    Nov 24, 2010 @ 02:10
    Sean Mooney
    0

    I have found that in order to get it to work I had to have a <form runat="server"> on the page, but even then it put the style sheet in the page whereever it is being called.

    Looks like it might be a bug in umbraco:

    http://umbraco.codeplex.com/workitem/21749

  • Heather Floyd 610 posts 1032 karma points MVP 6x c-trib
    Nov 24, 2010 @ 18:23
    Heather Floyd
    0

    Thanks for everyone's feedback. I suppose this is not really possible right now...

  • sun 403 posts 395 karma points
    Nov 25, 2010 @ 06:21
    sun
    0

    <xsl:variable name="HeadCSS" >
      <![CDATA[<style type="text/css">
      #s3slider
      {
        width:<xsl:value-of select="$RotatorNode/data[@alias='JCWidth']"/>px;
        height:<xsl:value-of select="$RotatorNode/data[@alias='JCHeight']"/>px;
      }
      #s3sliderContent
      {
        width:<xsl:value-of select="$RotatorNode/data[@alias='JCWidth']"/>px;
      }
      .s3sliderImage span {
        background-color:<xsl:value-of select="$RotatorNode/data[@alias='JCColor']"/>;
      }
      .s3sliderImage span.ctop,.s3sliderImage span.cbottom
      {
        width:<xsl:value-of select="($RotatorNode/data[@alias='JCWidth'])-26"/>px;  
      }
      .s3sliderImage span.cleft,.s3sliderImage span.cright,.s3sliderImage span.ccenter
      {
        width: <xsl:value-of select="($RotatorNode/data[@alias='JCCaptionWidth'])"/>;
        height:<xsl:value-of select="($RotatorNode/data[@alias='JCHeight'])-20"/>px;
      }
      .s3sliderImage span.ccenter
      {
        width: <xsl:value-of select="($RotatorNode/data[@alias='JCWidth'] div 2)"/>px;
        height:<xsl:value-of select="($RotatorNode/data[@alias='JCHeight'] div 3)"/>px;  
      }
      </style>]]>
      </xsl:variable>
      <xsl:value-of select="umbraco.library:RegisterClientScriptBlock('jCarouselCSS', $HeadCSS, 0)"/>

  • James Telfer 65 posts 165 karma points
    Nov 25, 2010 @ 07:34
    James Telfer
    0

    Why not just place the reference to the XSLT macro directly in the Head section where you wish it to be?

  • Heather Floyd 610 posts 1032 karma points MVP 6x c-trib
    Nov 30, 2010 @ 18:50
    Heather Floyd
    0

    @sun: I see where I made the syntax error with the CDATA... but even after correcting it is not showing up in the HEAD section.

    @James: The Macro includes both HEAD styles and script, as well as in-page content (divs and data, etc). I would need to break it into two macros for that to work... one to place in the HEAD and one to place in the BODY where the content should be displayed... I suppose that is an option, though not ideal.

    Thanks!

Please Sign in or register to post replies

Write your reply to:

Draft