Copied to clipboard

Flag this post as spam?

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


  • Lorenzo 5 posts 25 karma points
    Mar 14, 2011 @ 19:00
    Lorenzo
    0

    RenderMacroContent, UMBRACO_MACRO and HTML content

    Hi,

    I've a macro calling another macro and I'm having trouble rendering the html passed as parameter.

    this is the first macro:

    <xsl:for-each select="sql:GetData('xxx',$query,'profile')//profile" >
          <!--
        <umbraco:Macro Alias="CollapsibleItem" runat="server" Title="" Name="" Content="" Index="" ></umbraco:Macro>
        <?UMBRACO_MACRO macroAlias="CollapsibleItem" runat="server" Title="" Name="" Content="" Index="" ></?UMBRACO_MACRO>
        Fields from query: JobId, Role, Locations, Email, Description, DateCreated
        -->
          <xsl:variable name="mName" select="./Role"/>
          <xsl:variable name="mTitle" select="./Locations"/>
          <xsl:variable name="mContent" select="./Description"/>
          <xsl:variable name="macro">
            <xsl:text>&lt;?UMBRACO_MACRO macroAlias="MyItem" </xsl:text>
            <!-- Name -->
            <xsl:value-of select="concat(' Name=&quot;',$mName,'&quot;')"/>
            <!-- Title -->
            <xsl:value-of select="concat(' Title=&quot;',$mTitle,'&quot;')"/>
            <!-- Content -->
            <xsl:text disable-output-escaping="yes"> Content="&lt;p&gt;test&lt;/p&gt;"</xsl:text>
            <!-- Close Macro -->
            <xsl:text&gt;&lt;/?UMBRACO_MACRO&gt;</xsl:text>
          </xsl:variable>

          <xsl:value-of select="umbraco.library:RenderMacroContent($macro, $currentPage/@id)" disable-output-escaping="yes"/>
        </xsl:for-each>

    the html I would like to render is passed within the parameter "Content" and is a simple "<p>test</p>"

    and this is the macro that is used to render the first macro:

     <xsl:output method="html" omit-xml-declaration="yes"/>

      <xsl:param name="currentPage"/>
      <xsl:variable name="Title" select="/macro/Title" />
      <xsl:variable name="Name" select="/macro/Name" />
      <xsl:variable name="Content" select="/macro/Content" />
      <xsl:variable name="Index" select="/macro/Index" />
      <xsl:template match="/">

        <div>
          <div>
            <img src="/images/arrow.png" />
          </div>
          <div class="gridtextboxarticle">
            <a href="javascript:void(0)">
              <h2>
                <xsl:value-of select="$Name" />
                <span>
                  <xsl:value-of select="$Title" />
                </span>
              </h2>
            </a>
            <p>
              <xsl:value-of select="$Content" />
            </p>
          </div>
        </div>
      </xsl:template>

    the macro is rendered fine (I can see $Name and $Title) but the $Content is not appearing whatsoever or rendered in a wrong way.

    I tried to use a lot of method but now I'm stuck.

    Any clues?

    Thanks.

     

    P.S. the following code doesn't work properly

    From http://en.wikibooks.org/wiki/Umbraco/Reference/umbraco.library/RenderMacroContent

    ======================================================

    If you want to be able to just "cut & paste" the standard template macro code into your XSLT and have it encoded properly, add this bit of code to a new XSLT:

    <xsl:variable name="Macro"> <xsl:value-of select="{PUT YOUR 
    TEMPLATE MACRO CODE HERE}"/> </xsl:variable> <xsl:variable 
    name="MacroEncoded"> <xsl:value-of 
    select="umbraco.library:Replace(umbraco.library:Replace(umbraco.library:Replace($Macro,
     '"', '&quot;'), '>', '&gt;'), '<', '&lt;')"/> 
    </xsl:variable>

    Then use this to render the encoded XSLT to a test page in your browser (which you can then cut & paste into your XSLT code):

    <xsl:value-of select="$MacroEncoded" />
  • Lorenzo 5 posts 25 karma points
    Mar 15, 2011 @ 13:26
    Lorenzo
    0

    No worries guys :) I solved my problem in the following way:

    <xsl:variable name="list" select="sql:GetData('xxx',$query,'profile')//profile" />
        <xsl:variable name="listCount" select="count($list)"/>
        <xsl:for-each select="$list" >
          <xsl:variable name="mTitle" select="./Locations"/>
          <xsl:variable name="mContent" select="./Description"/>
          <xsl:variable name="mName" select="./Role"/>
          <xsl:variable name="mIndex" select="position()"/>
          <!--
          <umbraco:Macro Alias="CollapsibleItem" runat="server" Title="" Name="" Content="" Index="" ></umbraco:Macro>
          <?UMBRACO_MACRO macroAlias="CollapsibleItem" runat="server" Title="" Name="" Content="" Index="" ></?UMBRACO_MACRO>
          JobId, Role, Locations, Email, Description, DateCreated
          -->
          <xsl:variable name="macro">
            <![CDATA[<?UMBRACO_MACRO macroAlias="MyItem"]]>
            <![CDATA[ Name="]]><xsl:value-of select="$mName"/><![CDATA["]]>
            <![CDATA[ Index="]]><xsl:value-of select="$mIndex"/><![CDATA["]]>
            <![CDATA[ Title="]]><xsl:value-of select="$mTitle"/><![CDATA["]]>
            <![CDATA[ Content="]]><xsl:value-of select="umbraco.library:HtmlEncode($mContent)"/><![CDATA["]]>
            <![CDATA[ ></?UMBRACO_MACRO>]]>
          </xsl:variable>

          <xsl:value-of select="umbraco.library:RenderMacroContent($macro, $currentPage/@id)" disable-output-escaping="yes"/>
        </xsl:for-each>

    Cheers

    L.

     

Please Sign in or register to post replies

Write your reply to:

Draft