We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 30481
    • 33 Posts
    It is possible to have different ditto template depending of the site template ?

    Actullay when I change the template of my site i need to change te ditto template.... So if i want to propose two different template on my site, how the dittto call can select the correct template depending of the site template ?

    Thanks for your help.
      -------------------------------
      www.fabienletort.com
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      Each template will have the Ditto call in it somewhere, right? Well, your Ditto template is specified in the Ditto call’s parameters, so each one will specify a different Ditto template.
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 30481
        • 33 Posts
        not really... actuallly (as in the example site web) the ditto call is inside a document.
          -------------------------------
          www.fabienletort.com
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          In that case, perhaps a snippet, with a switch to return the chunk name depending on the current template in use.
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
            • 30481
            • 33 Posts
            ok, but where i can call this snippet ?

            If i call ditto with the a default chunk that contains this snippet call (used to select correct chunk) it does’nt work.

            whatever if this snippet return the chunk name or the chunk content.
            I think that is impossible to call a snippet from a ditto chunk ?
              -------------------------------
              www.fabienletort.com
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              Use the snippet as the value of the &tpl parameter. Have the snippet check the template ID (you can get it from the $modx->documentObject[] array, I believe) and have it return the name of the chunk depending on which template is being used.

              [!Ditto? &tpl=`[[getChunk]]` ... !]

              Or maybe use a template variable? Just have its default value be the name of the chunk you want to use, and only check the template you want it to be valid for.
                Studying MODX in the desert - http://sottwell.com
                Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                Join the Slack Community - http://modx.org
                • 6726
                • 7,075 Posts
                Another way to do this is use the PHx plugin...

                It all depends what you’re trying to achieve, but one thing I find myself using a lot is testing if a document is in a top folder (usually, those are very much akin to website sections and styles and/or templates, submenus, snippet calls often change between those) :

                [+phx:if=`[[UltimateParent? &id=`[*id*]` &topLevel=`1`]] `:is=`some_id`:then=`...chunk or snippet or whatever...`+]


                Now, if we use this logic to your purpose we have to tweak things a bit further :

                [+phx:if=`[[GetField? &docid=`[*id*]`  &field=`template`]]`:is=`id_of_such_template`:then=`...chunk or snippet or whatever...`+]


                Untested, but it should work...
                Of course with PHx you can use logic operators to refine this (and, or, lt, gt... etc).

                You might nevertheless have to use several calls, PHx doesn’t cover the case where you need to have several conditions tested at once.

                as usual, beware of cache issues with this kind of stuff tongue
                Actually, I might have a use for this so thanks for giving me the idea to use it grin
                  .: COO - Commerce Guys - Community Driven Innovation :.


                  MODx est l'outil id
                  • 30481
                  • 33 Posts
                  Thanks to all your replies.... i found a nice solution.

                  I purpose is to have different ditto template depending the website tempalte used on the page contaning the Ditto Call.
                  In this way it should be easy to move between template. Because, of course, when you change your website template you must often also make change in the different ditto template and other ’chunk template’.

                  With the ditto example, we can see that more generally it is all the webpage that is calling ditto that must be impacted: in this page you are calling Ditto and you are also using placeholders as [+page+], [+next+] and maybe also have Reflect call, as in the default example web site. So it is all this document which is very bind to the template used (davidm says the same thing in this post).

                  So, the better is to take all these call of this page and to put theses lines in a Chunk.

                  Take the default website as example

                  The ditto webpage is this one:
                  [[Ditto? &startID=`2` &summarize=`2` &removeChunk=`Comments` &tpl=`ditto_blog` &paginate=`1` &extenders=`summary,dateFilter` &paginateAlwaysShowLinks=`1` &tagData=`documentTags`]]
                  
                  Showing [+start+] - [+stop+] of [+total+] Articles
                  
                  [+previous+] [+pages+] [+next+]
                   
                  [[Reflect? &dittoSnippetParameters=`startID:2` &groupByYears=`0` &showItems=0` &tplMonth=`reflect_month_tpl`]]
                  


                  Ok just cut these lines and put this Chunk call in the document:
                  {{DittoCall}}
                  


                  Now Create the chunk DittoCall and copy the cutted line inside.

                  Yes, if we make a test now, all is as before. We are just calling a chunk that contains the lines which was in the document before.

                  Now create a new asset, called GetTemplateChunk:
                  <?php
                  global $table_prefix;
                      
                      /* Get parameter Value */
                      $chunk = isset($chunk) ? $chunk : "";
                      
                      $output = "";
                      
                      if ($chunk != "")
                      {
                          $templateId = $modx->documentObject['template'];
                          $templateName = 
                              $modx->db->getValue($modx->db->select("templatename", $table_prefix."site_templates", "id='$templateId'"));
                          
                          $output = $modx->getChunk($chunk."_".$templateName);
                          if ($output == "")
                          {
                              $output = $modx->getChunk($chunk."_default");
                          }
                      }
                      
                      return $output;
                  ?>
                  


                  This one is used to get a chunk that is website template dependant. The param is chunk.
                  The asset will return the content of the chunk with the following name: ’paramChunk’_’templateName’.
                  If this one does’nt exist it will return the content of the following chunk: ’paramChunk’_default.

                  Ok come back to our example.
                  Open the last created chunk ’DittoCall’ and Duplicate it with the following name: ’DittoCall_default’
                  Now in the Chunk ’DittoCall’ put only this line:
                  [[GetTemplateChunk? &chunk=`DittoCall`]]
                  


                  This call will return the content of the chunk named DittoCall_’templateName’ or DittoCall_default if not exist.

                  So if you make a test in this state, it is the DittoCall_default that will be return... All is as before.

                  Now, when creating a new website template, just put this new Template ’my_template’ as the default one for all your Document. (the Document contening the {{DittoCall}} line will have this new template as template).

                  Create a new Chunk "DittoCall_my_template". To customise All the Ditto page with the newTemplate.

                  Now test, yes, this it is this new Chunk that is used to renderer your document.


                  ==> Now when you change your template, you don’t need to modify all your important document (i.e. top folder document , often bind to templates). And you don’t loose all your parameter used with the website template used before. It is really smart and easy.




                  ---------------------
                  www.fabienletort.com

                    -------------------------------
                    www.fabienletort.com