We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 10930
    • 13 Posts
    I’m trying to get Ditto to pull a &tpl value from a TV. This is to allow the user to choose a custom chunk from a drop down list in the Edit Document area. I keep getting invalid chunk name warnings. Here’s what I’ve got:

    Ditto Call:
    [[Ditto? &documents=`[*documentID-1*]`&tpl=`[+documentID-1-Preview+]` ]]


    TV:
    documentID-1-Preview
    Input Type: DropDown List Menu
    Input Option Values:
    1==PortfolioSample1.tpl||2==PortfolioSample2.tpl||3==PortfolioSample3.tpl


    Chunk Sample:
    Name: PortfolioSample1.tpl
    <a href="[+PortfolioThumbnailFull+]" class="image-thumb" rel="lightbox" title="[+PreviewButtonImageTitle+]"><img src="[+PortfolioThumbnail+]" alt="Thumbtack" /></a>
    <h3>[+title+]</h3>
    <p>[+content+]</p>
    <p class="responsibility"><small>Our Responsibilties</small></p>
    <p class="skill">[+OurResponsibilities+]</p>
    <a href="[+PreviewButtonImage+]" class="buttonlink" rel="lightbox" title="[+PreviewButtonImageTitle+]">Preview</a>


    The result I get from the above is that my page renders, but in place of the ditto call I get this warning:

    &tpl either does not contain any placeholders or is an invalid chunk name, code block, or filename. Please check it.

    I double-checked my spelling on both the Chunk name and the TV name. I also manually typed in a &tpl value and everything worked fine. But when trying to pull the &tpl value from the TV it doesn’t work. Any other suggestions?

    Thanks!
      • 4172
      • 5,888 Posts
      you have to call TVs in your document with [*..........*], [+...........+] is only for placeholders e.g. in Ditto-chunks and so on and its better not to use special characters as ’-’ in your TV-Names.

      So try it with after renaming your TVs:
      [[Ditto? &documents=`[*documentID1*]`&tpl=`[*documentID1Preview*]` ]]
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 10930
        • 13 Posts
        Thanks for the response. That’s great stuff. I just started learning MODx two days ago, so these little tidbits are priceless!

        OK. I changed my Ditto to the following:
        [[Ditto? &documents=`[*documentID-1*]`&tpl=`[*documentID1Preview*]` ]]


        And I changed my TV name to documentID1Preview. Now when I try to render my page I get a blank white page with the following message:

        « MODx Parse Error »

        MODx encountered the following error while attempting to parse the requested resource:
        « PHP Parse Error »

        PHP error debug
        Error: Invalid argument supplied for foreach()
        Error type/ Nr.: Warning - 2
        File: /homepages/1/d193252204/htdocs/ShapingthePage_MODx/assets/snippets/ditto/classes/template.class.inc.php
        Line: 50
        Line 50 source: foreach ($templates as $tplName=>$tpl) {

        Parser timing
        MySQL: 0.0116 s (4 Requests)
        PHP: 0.4999 s
        Total: 0.5115 s

        Not sure how to trouble-shoot this. Any suggestions?

        Thanks!
          • 4172
          • 5,888 Posts
          what do you get, when you write only this instead of your ditto-call:

          <p>[*documentID-1*]</p>
          <p>[*documentID1Preview*]</p>
            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
            • 10930
            • 13 Posts
            When I do that my page renders properly and the value for [*documentID-1*] shows up, but the value for [*documentID1Preview*] is just empty.
              • 10930
              • 13 Posts
              And when I manually type in the &tpl value my page renders properly and it works, like so:

              [[Ditto? &documents=`[*documentID-1*]`&tpl=`PortfolioSample1.tpl` ]]


              But I’d like the user to be able to choose which chunk to use for the &tpl value from a dropdown menu.

              Based on the chunk name not showing up when the TV [*documentID1Preview*] is put in the template by itself, shows that it’s probably not a Ditto problem, but a TV problem. For some reason the value of the TV is not making it to the template when the template is rendered. I’ll include a screen shot of how my TV is set-up. Is there anything I’m doing wrong in the screen shot?


                • 4172
                • 5,888 Posts
                you should have one defaultvalue for your TV for example: ’PortfolioSample1.tpl’. So, if you haven’t choosen one of the options modx uses this value as default. Otherwise the value is empty.

                btw: you do not need to call your chunks .tpl at the end. You can simply call them PortfolioSample without the suffix .tpl
                  -------------------------------

                  you can buy me a beer, if you like MIGX

                  http://webcmsolutions.de/migx.html

                  Thanks!
                  • 10930
                  • 13 Posts
                  Thanks for the tip about the .tpl at the end of my chunk name. I put that on there as a visual reference to keep the names of all these pieces straight in my mind. I did take the .tpl off just to see if it made a difference and it didn’t.

                  I added a default value of PortfolioSample.tpl (no quotes, just plain) to the Default Value field and still get the same problem.

                  Could this have something to do with the use of (at)Bindings (@SELECT, @CHUNK, etc.)? I don’t claim to know how to use them, but they seem to be used within the Input Option Values field.

                  Might I need to use one of these bindings?
                    • 20413
                    • 2,877 Posts
                    Where is the ditto call? Maybe give all the templates - template access!
                      @hawproductions | http://mrhaw.com/

                      Infograph: MODX Advanced Install in 7 steps:
                      http://forums.modx.com/thread/96954/infograph-modx-advanced-install-in-7-steps

                      Recap: Portland, OR (PDX) MODX CMS Meetup, Oct 6, 2015. US Bancorp Tower
                      http://mrhaw.com/modx_portland_oregon_pdx_modx_cms_meetup_oct_2015_us_bancorp_tower
                      • 10930
                      • 13 Posts
                      Great point. The ditto call is within the template that has the [*documentID-1*] TV. But the [*documentID1Preview*] is in the template that the &tpl is trying to call.

                      In other words, [*documentID-1*] and [*documentID1Preview*] have template access to two separate templates. Maybe that explains why [*documentID-1*] is working in the ditto call, but [*documentID1Preview*] isn’t.

                      I extended the template access for [*documentID1Preview*] and now everything renders properly. Yeehaw!

                      The only problem with this from a user’s perspective is that they now need to choose what chunk a document uses from within another document. In other words, it’d be nice if I could keep the dropdown menu of chunk choices within the document that’s being pulled by the ditto call, and not within the document that uses the template that contains the ditto call. Does that make sense?