We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36818
    • 119 Posts
    I needed to build a site that aggregates different resources into one page. So it can be scrolled by anchors.
    The problem was to assign an individual Chunk-Template to every resource.
    For this purpose I tweaked the getResources-Snippet.


    1. Copy the getResources-Snippet (ver. 1.6.0) to getResourcesAltTpl (or any other name you wish)
    2. Open the newly created Snippet and add the following code:
    2a. around line 98 (default properties):
    $tplAltTV = !empty($tplAltTV) ? $tplAltTV : '';

    2b. after line 575:
        
    $tplAltTVx = $properties[$tvPrefix . $tplAltTV];
        if (!empty($tplAltTV) && empty($resourceTpl)) {
    		$resourceTpl = parseTpl($tplAltTVx,$properties);
    	}

    just before:
    if (!empty($tpl) && empty($resourceTpl)) {


    3. Create a TV (type listbox). You can automatically populate it with the names of the chunks you need with
    @SELECT name FROM modx_site_htmlsnippets WHERE category = (number of the category you ordered your chunks)


    4. Assign a chunk template to every resource via TV
    5. Use the new Snippet as follwing:
      [[!getResourcesAltTpl? 
         &includeContent=`1` 
         &parents=`[[*parent]]` 
         &sortdir=`ASC` 
         &sortby=`menuindex`
         &tplAltTV=`Name_of_your_TV`
         &includeTVs=`1`
         &processTVs=`0`
       ]]



    Hope this helps some of you.
    The additional code in the snippet might not be most elegant one (and probabely it is not even safe/right), but it helped me.

    Best wishes.
      • 33987 ☆ A M B ☆
      • 197 Posts
      Thanks for sharing! Isn't there a way to do this without hacking? For example, in your default chunk you just call another chunk, based on the [[+tplAltTV]] value?

      Fox example, chunk:
      [[+tplAltTV:neq=``:then=`
          <!-- template to use when no alternative template was selected -->
      `:else=`
          <!-- somehow include another chunk based on the TV value. Dunno if this works: -->
          @CHUNK [[+tplAltTV]]
      `]]
      


      Something tells me that '@CHUNK [[+tplAltTV]] does not work, but I can't test this right now. Just got it here: http://rtfm.modx.com/display/revolution20/CHUNK+Binding
        Sterc Internet & Marketing | MODX Founding Partner | Chairman of the MODX Advisory Board

        In need of a MODX consult? Try our MODX Developers Experts!
        • 42046
        • 436 Posts
        Also have a look at conditional templates: https://github.com/opengeek/getResources/pull/58
          • 36818
          • 119 Posts
          Quote from: nomark at Aug 06, 2013, 01:23 PM
          Thanks for sharing! Isn't there a way to do this without hacking? For example, in your default chunk you just call another chunk, based on the [[+tplAltTV]] value?

          Fox example, chunk:
          [[+tplAltTV:neq=``:then=`
              <!-- template to use when no alternative template was selected -->
          `:else=`
              <!-- somehow include another chunk based on the TV value. Dunno if this works: -->
              @CHUNK [[+tplAltTV]]
          `]]
          


          Something tells me that '@CHUNK [[+tplAltTV]] does not work, but I can't test this right now. Just got it here: http://rtfm.modx.com/display/revolution20/CHUNK+Binding

          Hi GP,
          your thoughts were also my first idea. Without remembering all the details (will have a look at them tomorrow):
          - I wanted a more flexible solution: creating chunks as templates for a resource called by getResources and using this chunk in a TV without touching the getResources-call nor the "gateway"-chunk
          - my chunk that called the other chunk was something like
          [[$[[+tplAltTV]]]]
          , but it lead to strange behaviour (same resource showed up twice)

          I never had a look at the bindings at all. It looks very powerful, but also a little bit spooky to me ('cause they are powerful...). But I will give them a try.

            • 36818
            • 119 Posts
            Quote from: absent42 at Aug 06, 2013, 02:35 PM
            Also have a look at conditional templates: https://github.com/opengeek/getResources/pull/58

            Thanks, Dan.
            Stumbled upon the conditional templates yesterday. The idea is great, but as with the chunk-calls-another-chunk-solution, I wanted a more "flexible" way doing this. Knowing that it is my personal opinion: I don't like it to ajust a snippet call when I change/add/remove/rename another element the call relies on.
            Just a straight forward solution: resource A shall be parsed with chunk B, and so one.

            And my second point: there is nothing in the resources that could be compared against a condition. In my case it is the site-start-resource that calls the getResource snippet and pulls together one big html-file filled with the content of some other resources. So the templates assigned to the resources are irrelevant (as showed in the example on github).

            Anyway, thanks you Dan and GP for your inputs. Guys like you are one of many reasons I like MODX very much: great (almost too) flexible CMS, and wonderful, competent people supporting it.

            cu
            Fabian
              • 37221 ☆ A M B ☆
              • 5 Posts
              I have solved this by adding the property 'processTVs=`1` to the default getResources call.
              In this case the query for the TV should be:

              @SELECT `name`,CONCAT('@CHUNK ',`name`) FROM `modx_site_htmlsnippets` WHERE `category` = (number of the category you ordered your chunks)


              That way there is no need for an alternative getResources snippet.