Copied to clipboard

Flag this post as spam?

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


  • Max 144 posts 166 karma points
    Jan 18, 2012 @ 09:25
    Max
    0

    calling a macro in XSLT

    Hi i have a xslt file which will call an existing macro within umbraco

    i need some suggestion  on how to tag  the macros in xslt

    this is my existing macro

    <umbraco:Macro Alias="AdmiralLogControl" runat="server">

     

    here isn my new xslt :

    <xsl:variable name="domainName">  
          <xsl:value-of select="umbraco.library:RequestServerVariables('HTTP_HOST')" />
        </xsl:variable> 
    <xsl:template match="/">

    <!-- start writing XSLT -->
      <!-- determine which banner to show --> 
      <xsl:choose>  
        <xsl:when test="$domainName = 'bd.admiral.dk'">     
          <!-- code for banner here -->  
          
        </xsl:when>   
        <xsl:when test="$domainName = 'dk.admiral.dk'">   
          <!-- code for alternative banner goes here -->  
          
        </xsl:when>  
        <xsl:otherwise>     
          <!-- code for default banner goes here --> 
          
        <!--tag it here-->


      
          
        </xsl:otherwise> 
      </xsl:choose> 

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 7x admin c-trib
    Jan 18, 2012 @ 09:35
    Chriztian Steinmeier
    0

    Hi Max,

    I don't fully understand what you want to do - but if you're trying to render the AdmiralLogControl macro inside of the XSLT macro, you need to know that you can only render another XSLT macro this way. It's just not possible to render a UserControl macro from an XSLT macro.

    But this beoing Umbraco, there's always a way to get what you want, we just need to know a little more...

    /Chriztian 

  • Max 144 posts 166 karma points
    Jan 18, 2012 @ 10:06
    Max
    0

    how about rendering the macro in xslt method any code examples would be useful

     

  • Michael Latouche 504 posts 819 karma points MVP 3x c-trib
    Jan 18, 2012 @ 10:13
    Michael Latouche
    0

    Hi Max,

    In order to do this you will need to use the RenderMacroContent library method. You can find more info on http://our.umbraco.org/wiki/reference/umbracolibrary/rendermacrocontent

    Cheers,

    Michael.

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 7x admin c-trib
    Jan 18, 2012 @ 10:18
    Chriztian Steinmeier
    0

    Hi Max,

    To render a macro form XSLT, you call the RenderMacroContent() extension in umbraco.library

    /Chriztian

  • Rodion Novoselov 694 posts 859 karma points
    Jan 18, 2012 @ 11:10
    Rodion Novoselov
    0
    It's just not possible to render a UserControl macro from an XSLT macro.
    

     

    Critzian, thx, that's a usefull tip - personally I've never been aware of this limitation before, perhaps because I started with umbraco from 4.7 and hardly ever used webcontrol macros at all (I strongly prefer razor).

    I'm wondering is there the same limitation for razor macros?

  • Max 144 posts 166 karma points
    Jan 18, 2012 @ 11:18
    Max
    0

    it does not seem to work since its .net user control any other options ??

     

  • Michael Latouche 504 posts 819 karma points MVP 3x c-trib
    Jan 18, 2012 @ 11:26
    Michael Latouche
    0

    Hi Max,

    Maybe you could put your macro in your template file, in an invisible div. And then in the "otherwise" clause of your xslt, you write the javascript/jquery code that makes the div visible.

    Cheers,

    Michael.

  • Max 144 posts 166 karma points
    Jan 18, 2012 @ 13:18
    Max
    0

    its done here is the code

     <xsl:variable name="domainName">  
          <xsl:value-of select="umbraco.library:RequestServerVariables('HTTP_HOST')" />
        </xsl:variable> 
    <xsl:template match="/">

    <!-- start writing XSLT -->
      <!-- determine which banner to show --> 
      <xsl:choose>  
        <xsl:when test="$domainName = 'bd.admiral.dk'">     
          <!-- code for banner here -->  
             <xsl:value-of select="umbraco.library:RenderMacroContent('&lt;?UMBRACO_MACRO macroAlias=&quot;AdmiralLogBDControl&quot; &gt;&lt;/?UMBRACO_MACRO&gt;', $currentPage/@id)" disable-output-escaping="yes" />
          
        </xsl:when>   
        <xsl:when test="$domainName = 'dk.admiral.dk'">   
          <!-- code for alternative banner goes here -->  
               <xsl:value-of select="umbraco.library:RenderMacroContent('&lt;?UMBRACO_MACRO macroAlias=&quot;AdmiralLogDKControl&quot; &gt;&lt;/?UMBRACO_MACRO&gt;', $currentPage/@id)" disable-output-escaping="yes" />
          
        </xsl:when>  
        <xsl:otherwise>     
          <!-- code for default banner goes here --> 
        <xsl:value-of select="umbraco.library:RenderMacroContent('&lt;?UMBRACO_MACRO macroAlias=&quot;AdmiralLogControl&quot; &gt;&lt;/?UMBRACO_MACRO&gt;', $currentPage/@id)" disable-output-escaping="yes" />
        
        </xsl:otherwise> 
      </xsl:choose> 

    </xsl:template>

  • Rodion Novoselov 694 posts 859 karma points
    Jan 18, 2012 @ 13:27
    Rodion Novoselov
    0

    Max, I think you could use a control macro as your "wrapping" macro instead of an xslt one. There shouldn't be a problem with using control macros inside another control macro via <umbraco:Macro> control. You could place several <umbraco:Macro> controls inside an <asp:MultiView> control or add a required one programmatically to some placeholder or like that - anything that you can do with usual asp.net controls.

  • Michael Latouche 504 posts 819 karma points MVP 3x c-trib
    Jan 18, 2012 @ 13:41
    Michael Latouche
    0

    Max,

    Does the XSLT you posted actually work then? With .Net controls?

    Cheers,

    Michael.

  • Rodion Novoselov 694 posts 859 karma points
    Jan 18, 2012 @ 14:36
    Rodion Novoselov
    0

    As I understand I also suppose that custom rendering of a user control macro from an xslt one actually should work - the thing that won't work is processing a later postback by this control if there's any afterwards.

  • Max 144 posts 166 karma points
    Jan 19, 2012 @ 06:09
    Max
    0

    that script consist of 3 .net user controls it worked perfectly fine for me ..

    thank you

     

  • Michael Latouche 504 posts 819 karma points MVP 3x c-trib
    Jan 19, 2012 @ 09:59
    Michael Latouche
    0

    Hi Max,

    Good to hear! Can you maybe mark one of the post mentioning RenderMacroContent as the solution to your issue? This will help other people with the same issue to spot the solution. Thanks!

    Cheers,

    Michael.

  • Garrett Fisher 341 posts 496 karma points
    Oct 12, 2016 @ 18:32
    Garrett Fisher
    0

    This isn't working for me. Does RenderMacroContent() work in Umbraco 7? My macro output is:

    <Macro: (,)> 
    

    Can anyone help? I have a containing XSLT macro which contains logic on whether or not to display a certain other macro; takes the other macro as a passed-in paramter and that string is coming in fine but the macro output is not displaying/working.

    Here is the code from the containing XSLT macro:

    ​<xsl:output method="xml" omit-xml-declaration="yes"/>
    
    <xsl:param name="currentPage"/>
    
    <xsl:variable name="useMacro" select="/macro/macroToCall"/>
    
    <xsl:template match="/">
    
    <xsl:variable name="homeNode" select="$currentPage/ancestor-or-self::Home[@isDoc]"/>
    <xsl:variable name="showRegister" select="$homeNode/useGigya"/>
    
    <xsl:if test="$showRegister = 1">
        <xsl:value-of select="umbraco.library:RenderMacroContent('&lt;?UMBRACO_MACRO macroAlias=&quot;$useMacro&quot; &gt;&lt;/?UMBRACO_MACRO&gt;', $homeNode/@id)" disable-output-escaping="yes" />
    </xsl:if>
    
    </xsl:template>
    

    Thanks,

    Garrett

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 7x admin c-trib
    Oct 12, 2016 @ 23:14
    Chriztian Steinmeier
    0

    Hi Garrett,

    The way you're sending the string to the function, actually makes it try to render a macro called $useMacro - you need to put the contents of the variable into the string, like this:

    <xsl:if test="$showRegister = 1">
        <xsl:value-of select="umbraco.library:RenderMacroContent(concat('&lt;?UMBRACO_MACRO macroAlias=&quot;', $useMacro, '&quot; &gt;&lt;/?UMBRACO_MACRO&gt;'), $homeNode/@id)" disable-output-escaping="yes" />
    </xsl:if>
    

    Hope that helps,

    /Chriztian

  • Garrett Fisher 341 posts 496 karma points
    Oct 13, 2016 @ 15:08
    Garrett Fisher
    0

    That does help..... and WORKS! Chriztian -- you've done it again: you've saved my ass. THANK YOU!!!

    //Garrett

Please Sign in or register to post replies

Write your reply to:

Draft