Copied to clipboard

Flag this post as spam?

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


  • Greg Berlin 818 posts 634 karma points
    Jul 05, 2010 @ 14:05
    Greg Berlin
    0

    How to Render a Doc Type (using its Template) from a Macro

    I'm trying to create a module system, whereby a user can select which 'modules' they want to insert into sidebars on their page.

    I thought I'd do it by creating the following node structure (in data section of site, so not rendered to pages)?

    Modules
     - Left Modules
        - Navigation menu
        - Donation Button
        - Another info module
     - Right Modules
        - Newsletter Signup
        - Some specific content

    Then, on each page i'd include 2 multi-content pickers, whereby they can choose which modules they'd like on that page, reorder them, etc.  

    So far so good... but the problem comes in when i want to render the modules. I can have each module have its own template, which would just be a chunk of html with the relevant bits of the module entered into the relevant spots.  The template might even include a macro (if the module is to render lists of items for example).

    I need a way to get the rendered output of that module from an xslt, and output it into the page into which it is inserted (basically every page of the site, and it'd use the list of modules selected by the content pickers to figure out which items to get - using documentIds i guess.)

    Has anybody done this before?  Is it do-able?  Or is there another way somebody has thought up to accomplish the same thing... i bet there would be - there's many ways to skin a cat - and this cat i'm sure has just begged to be skinned on many an occasion in the past.  :)

    Thanks all

    Greg

     

     

  • Rich Green 2246 posts 4008 karma points
    Jul 05, 2010 @ 14:22
    Rich Green
    0

    Hi,

    I'm not sure why each module would need a template or a macro?

    The design could be wrapped around the module in the XSLT, so it would just be a case of looping around each module and outputting the HTML?

    If each module has a different design then I would create a different doc type for each design and then within the XSLT call XSLT templates depending on which design is required.

    I've used this on a few sites and works really well. We also added the ability for modules to be set at any level and inherited downwards, which can be overridden.  This means the client can set and order the modules at a high level and doesn't need to do this for every single page.

    Hope I've understood and this makes sense!

    Rich

     

     

     

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Jul 05, 2010 @ 14:25
    Chriztian Steinmeier
    0

    Hi Greg - this sounds exactly like the new MacroContainer in Umbraco 4.5 - maybe you should check that out?

    /Chriztian

  • Greg Berlin 818 posts 634 karma points
    Jul 05, 2010 @ 14:32
    Greg Berlin
    0

    hey Rich,

    Thanks for the quick response.  The modules would indeed have different designs as their content is completely different (one is a newsletter signup form, one is a navigation menu, etc etc).

    I guess i could hard code the calling of xslt templates based on the documentIds (or documentType aliases) of the selected modules - just feels a little dirty i guess.

    I would definitely use inheritence here, as every page (including the root page, which i've setup just to create a base for all child pages to inherit from) would have these 2 pickers, so any page that doesn't choose anything would automatically inherit their parents' items.  Makes sense.  Did you use a multi content picker for the module selection?

    I just found this blog post: http://blog.hendyracher.co.uk/sidebar-widgets-with-umbraco-v4/

    Which implements exactly what i'm after, but uses a .net UserControl  and a repeater control. Doing it this way would add a whole new layer of complexity (for modules that render lists for example)... i'd much prefer to just stick to the neat and easy xslt implementation.

  • Greg Berlin 818 posts 634 karma points
    Jul 05, 2010 @ 14:34
    Greg Berlin
    0

    yeah, i've read about the macro container Chriztian, but unfortunately this project has a super tight deadline (need to deliver next monday, and only started devving last week... all in my spare time)... and i've built it on 4.0.... pity, as it sounds like it'd fit the role perfectly.

  • Rich Green 2246 posts 4008 karma points
    Jul 05, 2010 @ 14:41
    Rich Green
    0

    We used Tribal Xpath Node relations

    However the multipicker will do exactly the same job (not sure what the inherit ancestor tick box does but we don't use it).

    As for the layout being in XSLT, i'm not sure if it's best practice. You could put each layout in its own XSLT files, which would be a little cleaner?

    Rich

  • Greg Berlin 818 posts 634 karma points
    Jul 05, 2010 @ 14:47
    Greg Berlin
    0

    Yeah i'm thinking MultiPicker, selecting from a bunch of nodes is the way forward... and having xslt's to render the contents of the modules.

    Its gonna be fun sending the configs of each module to the template, and then from the template to the master macro, and then from the master macro to the child macros.  my brain hurts just thinking about it.  eek.

    Thanks for the tips, i think i have enough to power on. :)

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Jul 05, 2010 @ 14:50
    Jeroen Breuer
    0

    @Rich Green The inhert ancestor checkbox of the Tribal Xpath Node relations becomes active if the parent node also has this property (with the same property name). You can than choose to use the nodes you selected in the parent.

    @Greg If you want to use modules on a sidebar you might want to read this blog: http://blog.hendyracher.co.uk/sidebar-widgets-with-umbraco-v4/

     

  • Greg Berlin 818 posts 634 karma points
    Jul 05, 2010 @ 15:01
    Greg Berlin
    0

    @Jeroen, yeah i read that blog... read my post about 5 up from this one.  Using .Net user controls - trying to avoid that - seems unnecessary for this problem.

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Jul 05, 2010 @ 15:23
    Jeroen Breuer
    1

    Sorry replied a bit too fast without reading the entire topic. I used it too (see my reaction: http://blog.hendyracher.co.uk/sidebar-widgets-with-umbraco-v4/#comment-3999) and it was done in no time. There is also a marco picker for Umbraco 4.0. Maybe you can use that: http://our.umbraco.org/projects/backoffice-extensions/macropicker

  • Greg Berlin 818 posts 634 karma points
    Jul 06, 2010 @ 02:05
    Greg Berlin
    0

    @Jeroen, yeah i'm sure its easy to do, however it does not accomplish my needs as it only renders the main content of the item. Sure i could render out other parts of the item fairly easily, but some of them will be generated lists of items... and i dont want to go down the linq to umbraco path for this project.

     

    I think i'll run with the macro solution... while not 100% ideal, it'll do the trick for now. I wonder if i put the macro picker on the doc types, and select which macro to render the doc type with (instead of template)... then when the user chooses items of that doc type, in the master macro if i could determine which macro is selected, and then insert it passing in parameters from the item.  

    sorry to be thinking out loud here... i'll give it a bash tonight when i get home... i dont see why it wouldn't work.. and then i'd be getting around the need to hardcode anythign in the macros :)

     

     

  • Greg Berlin 818 posts 634 karma points
    Jul 10, 2010 @ 13:05
    Greg Berlin
    0

    Hmmm... so back to this one.  I'm trying to call macros from my xslt using the umbraco.library:RenderMacroContents function, however it doesnt seem to work (no errors, just doesn't render anything).

    My research seems to indicate that this doesn't work with master pages... is this true, or is there a solution?

    Here's the code i'm using:

        <xsl:variable name="Node" select="$currentPage" />   

        <xsl:variable name="macro">

          <xsl:text>&lt;umbraco:Macro runat="server" Alias="module_right_pressreleases" source="1165" /></xsl:text>

        </xsl:variable>

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

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

      </xsl:template>

    $macro outputs the following:

    <umbraco:Macro runat="server" Alias="module_right_pressreleases" source="1165" />

    which looks pretty good to me.  But it's not rendering the content of that macro.

    Any suggestions?

  • Greg Berlin 818 posts 634 karma points
    Jul 10, 2010 @ 13:25
    Greg Berlin
    0

    Hooray i got it.. here's my solution i n case somebody is interested:

      <xsl:stylesheet
        version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:msxml="urn:schemas-microsoft-com:xslt"
        xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets"
        exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">
    
      <xsl:output method="xml" omit-xml-declaration="yes" />
    
      <!--<xsl:param name="currentPage"/>-->
    
      <!-- VERTICAL RESPONSE MACRO: -->
      <xsl:include href="module_right_veritcalresponse.xslt" />
    
      <!-- PRESS RELEASES MACRO: -->
      <xsl:variable name="source" select="1165"/>
      <xsl:include href="module_right_pressreleases.xslt" />
    
      <xsl:template match="/">
    
        <!-- HOME PAGE -->
        <xsl:if test="$currentPage/@nodeName='Home'">
          <xsl:call-template name="module_right_verticalresponse" />
        </xsl:if>
    
        <!-- UPDATES PAGE -->
        <xsl:if test="$currentPage/@nodeName='Updates'">
          <xsl:call-template name="module_right_pressreleases" />
        </xsl:if>      
    
      </xsl:template>
    
    </xsl:stylesheet>
    
  • Greg Berlin 818 posts 634 karma points
    Oct 26, 2010 @ 14:47
    Greg Berlin
    1

    I ended up using Hendy's approach with a .net user control, (http://blog.hendyracher.co.uk/sidebar-widgets-with-umbraco-v4/comment-page-1/#comment-5311), and well i'm blown away at how easy it was to implement.  All up about 2.5 hours and i've created the doc types, module nodes, pickers, and rendering.  Brilliant.

    Got some tidying up to do now (proper info in the content items, styles, etc)... but other than that, all done.  Jeez i love umbraco!

Please Sign in or register to post replies

Write your reply to:

Draft