Copied to clipboard

Flag this post as spam?

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


  • dominik 711 posts 733 karma points
    Sep 08, 2011 @ 14:54
    dominik
    1

    Use Macro in Macro

    hello,

    how can i use a macro inside another macro?

    I have one macro which shows a sidebar and inside this macro i want to place another marcro with some properties. This macro should be use from TinyMCE

    Everytime i place something in this macro it is not rendered in the frontend

    Is there any problem with using macros in macros?

    If yes how can i solve this?

     

    Thanks

  • dominik 711 posts 733 karma points
    Sep 08, 2011 @ 15:07
    dominik
    0

    it displays

    <?UMBRACO_MACRO in the source code for this macro
  • Euan Rae 105 posts 135 karma points
    Sep 08, 2011 @ 15:23
    Euan Rae
    0

    If you're using xslt's you can use the umbraco.library:RenderMacro function. * This won't work for usercontrols

  • dominik 711 posts 733 karma points
    Sep 08, 2011 @ 15:25
    dominik
    0

    so where i have to use this? inside the first xslt macro?

  • Euan Rae 105 posts 135 karma points
    Sep 08, 2011 @ 15:26
    Euan Rae
    0

    Yep, in the first macro, use <xsl:value-of select="umbraco.library:RenderMacro(innerMacroName)"/>

  • Euan Rae 105 posts 135 karma points
    Sep 08, 2011 @ 15:40
    Euan Rae
    0

    Although, the better way to do this would be:

    In the first xslt macro, make a reference to the second xslt macro.  Once you've done that, you can call any template in the second macro

  • dominik 711 posts 733 karma points
    Sep 08, 2011 @ 16:44
    dominik
    0

    ok but i need the propertie window from the second macro in my content editor - how can i achieve this

    If i place it directly in the first xslt script i can not use it with properties out of my richtext editor.

    So my first macro generates a sidebar. The second macro is to show a button with properties (cssclass, text, link) this should be placed inside the richtext.

    In the editor all looks good and the content is rendered but on the webseite i get only

    <?UMBRACO_MACRO in the source code forthis macro
  • Euan Rae 105 posts 135 karma points
    Sep 08, 2011 @ 16:46
    Euan Rae
    0

    Can you please paste in the code from the 2 xslt files so I can get a clear look at what you're trying to do?

  • dominik 711 posts 733 karma points
    Sep 09, 2011 @ 08:36
    dominik
    0

    so first xslt script is:

        <xsl:if test="$currentPage/sidebarContent != '' ">
          <div class="content">
             <xsl:value-of select="$currentPage/sidebarContent" disable-output-escaping="yes"/>
          </div>
        </xsl:if>

    second xslt script is only for displaying a button with some macro properties "name", "link" and "css class".

    This should be shown inside the <div> of xslt script 1.

    But i have to place it in the content Richtext editor field of "sidebarContent" so i am prompted for the properties, name, cssclass and link.

    So what should it do:

    The user/marketing people will place an order now button and link it to a site. Select a css class and name it with a dictonary item inside the sidbear (with Richtext editor)

    So sidebar is working correct but the button is not displayed :-(

    Thanks

     

  • Mike Chambers 636 posts 1253 karma points c-trib
    Sep 09, 2011 @ 10:17
    Mike Chambers
    0

    Might be a little late to this thread...

    but did you see....

    http://our.umbraco.org/wiki/reference/umbracolibrary/rendermacrocontent

    I tend to use it like this...

    <xsl:variable name="macroChaining" select="concat('&lt;?UMBRACO_MACRO HideCategory=&quot;',$hideCategory,
    '&quot; AbstractLength=&quot;',$abstractLength,
    '&quot; ShowThumbnail=&quot;',$showThumbnail,
    '&quot; ThumbnailSize=&quot;',$thumbnailSize,
    '&quot; Class=&quot;',$class,
    '&quot; macroAlias=&quot;RelatedList&quot; runat=&quot;server&quot;&gt;&lt;/?UMBRACO_MACRO&gt;')"
    />

    makes it a little easier to read. :-)

    and then in the template match

    <xsl:value-of select="umbraco.library:RenderMacroContent($macroChaining, $currentPage/@id)" disable-output-escaping="yes"/>    
  • dominik 711 posts 733 karma points
    Sep 09, 2011 @ 11:06
    dominik
    0

    Hi Mike,

    Sorry I dont understand - i am using Umbraco 4.7 and not an old one. So I think i have to use the new type of writing macros or?

    <umbraco:Macro Alias="Button" runat="server"></umbraco:Macro>

    But if i do so it is not rendered in the frontend -

    I think there is a problem of rendering a macro inside another macro. THis seems to be an umbraco error or?

     

    Thanks

  • Euan Rae 105 posts 135 karma points
    Sep 09, 2011 @ 12:16
    Euan Rae
    0

    Are you trying to render a usercontrol macro inside an xslt macro?  If so, you can't do that

  • dominik 711 posts 733 karma points
    Sep 09, 2011 @ 12:28
    dominik
    0

    No it is not a usercontrol.

    Both are xslt macros

    I want to render a xslt macro inside my other xslt macro - but it is not rendered in the frontend

  • Euan Rae 105 posts 135 karma points
    Sep 09, 2011 @ 12:35
    Euan Rae
    0

    OK, instead of trying to call a macro from another macro, what you should do is, in the 'outer' macro, create a reference to the 'inner' macro using an <xsl:import>

    e.g.

    <xsl:import href="/inner-macro.xsl"/>

    Once you have this, you can use

    <xsl:call-template name="templateName"/>  and call any templates in your inner macro from your outer macro

     

     

     

     

     

     

     

     

     

  • dominik 711 posts 733 karma points
    Sep 09, 2011 @ 13:11
    dominik
    0

    hey, if i do so

    i can not get this working in the inner xslt:

    <xsl:variable name="text" select="/macro/text"/>
    <xsl:variable name="class" select="/macro/class"/>   

    <xsl:template name="showButton">
         <xsl:value-of select="$text"/>
    </xsl:template>


    It looks like it is not getting macro parameters
    Fixed texts are working

  • Euan Rae 105 posts 135 karma points
    Sep 09, 2011 @ 13:14
    Euan Rae
    0

    You will need to pass the parameters explicity

    So, in the template in the inner macro, create template paramaters, then pass the parameters

    e.g.

    <xsl:template name="showButton">

    <xsl:with-param name="css" select="$css"/>

        <!-- Do this for all parameters -->

    </xsl:template>

  • dominik 711 posts 733 karma points
    Sep 09, 2011 @ 13:17
    dominik
    0

    'xsl:with-param' cannot be a child of the 'xsl:template' element.

  • Mike Chambers 636 posts 1253 karma points c-trib
    Sep 09, 2011 @ 13:25
    Mike Chambers
    0

    if youy read the wiki, you'll see that even for u4.7 you use the old method in order to use the render macro content...

     

    I can confirm that I'm using the exact same method in 4.5.2 and 4.7 and 4.7.1 nightly and it works in all instances :-)

  • dominik 711 posts 733 karma points
    Sep 09, 2011 @ 13:26
    dominik
    0

    i now trying the xsl:import method but paramaters  are not working

  • Mike Chambers 636 posts 1253 karma points c-trib
    Sep 09, 2011 @ 13:29
    Mike Chambers
    0

    if you read the wiki, you'll see that even for u4.7 you use the old method in order to use the render macro content...

     

    I can confirm that I'm using the exact same method as I have above in 4.5.2 and 4.7 and 4.7.1 nightly and it works in all instances :-)

  • dominik 711 posts 733 karma points
    Sep 09, 2011 @ 13:32
    dominik
    0

    I think the xsl:import method is a better and easier solution but it looks likeI can not use parameters in the inner xslt script.

  • Euan Rae 105 posts 135 karma points
    Sep 09, 2011 @ 13:34
    Euan Rae
    0

    you can use parameters in the inner xslt script, I've done it quite a few times

    You do it like so:

    <xsl:template name="showButton">

    <xsl:with-param name="css" select="$css"/>

    </xsl:template>

    Could you post your xslts so I can have a look?

  • dominik 711 posts 733 karma points
    Sep 09, 2011 @ 13:35
    dominik
    0

    if i try this i get

    'xsl:with-param' cannot be a child of the 'xsl:template' element.


  • Euan Rae 105 posts 135 karma points
    Sep 09, 2011 @ 13:44
    Euan Rae
    0

    Oh, I see.

    On the inner template, you do this

    <xsl:template name="innerMacroTemplate">

    <xsl:param name="myParam"/>

    </xsl:template>

    Then when you call the template, you do this

    <xsl:call-template name="innerMacroTemplate">

    <xsl:with-param name="myParam" select"$valueToPass"/>

    </xsl:call-template>

     

  • dominik 711 posts 733 karma points
    Sep 09, 2011 @ 13:47
    dominik
    0

    but the value / macro property is only known by the inner template. So i think the outer template will not know $valueToPass because it is a value of the inner xslt script

  • Euan Rae 105 posts 135 karma points
    Sep 09, 2011 @ 13:53
    Euan Rae
    0

    OK, if the inner property already knows the value, then it doesn't need to be passed by the outer template

  • dominik 711 posts 733 karma points
    Sep 09, 2011 @ 13:56
    dominik
    0

    yes but it does not work

    here is my outer xslt:

    <xsl:call-template name="showButton"></xsl:call-template>

    And this is the inner xslt


     <xsl:variable name="text" select="/macro/text"/>    
    <xsl:variable name="class" select="/macro/class"/>    
        
    <xsl:template name="showButton">

      <h3>
         <xsl:value-of select="$text"/>
      </h3>

    </xsl:template>

     

    But  text is not displayed.


  • Euan Rae 105 posts 135 karma points
    Sep 09, 2011 @ 14:00
    Euan Rae
    0

    OK, you need to pass the value from the outer macro to the inner macro like so:

     

    Outer Macro

    <xsl:param name="text" select="/macro/text"/>    

    <xsl:param name="class" select="/macro/class"/> 

     

    <xsl:call-template name="showButton">

    <xsl:with-param name="text" select="$text"/>

    <xsl:with-param name="class" select="$class"/>

    </xsl:call-template>

     

    Inner Macro

    <xsl:template name="showButton">

    <xsl:param name="text"/>

    <xsl:param name="class"/>

      <h3>

         <xsl:value-of select="$text"/>

      </h3>

     

    </xsl:template>

  • dominik 711 posts 733 karma points
    Sep 09, 2011 @ 14:05
    dominik
    0

    But "/macro/text/" and "/macro/class" are properties of the inner xslt macro and not known by the outer xslt script I think.

    Will outer xslt will know the macro properties of the innner xslt automatically?

     

  • Euan Rae 105 posts 135 karma points
    Sep 09, 2011 @ 14:51
    Euan Rae
    0

    Make them macro parameters of the outer xslt

  • Euan Rae 105 posts 135 karma points
    Sep 09, 2011 @ 14:57
    Euan Rae
    0

    I should clarify;

    using this method, calling the inner xslt with <xsl:import> method means that you are calling the inner xslt straight through xslt, it has nothing to do with umbraco parameters

  • dominik 711 posts 733 karma points
    Sep 09, 2011 @ 15:24
    dominik
    0

    Hi Euan,

    I could not get it working with your solution because the macro properties depends on the inner xslt script.

    I tried Mikes solution and this works


    Thanks a lot for your help Euan and Mike

Please Sign in or register to post replies

Write your reply to:

Draft