We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 22448
    • 241 Posts
    I need to choose which documents to include in a Ditto call based on a value of a TV. I’ve tried many different variations on the theme but keep getting SQL errors.

    The basic Ditto call works just fine:
    [[Ditto?documents=`[*optionsTempRoof*]` &tpl=`@FILE:assets/chunks/templates/product_option_related_tpl.chk` ]]


    Then i turned off the built-in PHx and tried the conditional statement like so:
    [[Ditto?documents=`[*phx:input=`[*optionsTempRoof*]`:len:gt=`0`:then=`[*optionsTempRoof*]`:else=`[*optionsPermRoof*]`*]` &phx=`0` &tpl=`@FILE:assets/chunks/templates/product_option_related_tpl.chk` ]]


    which resulted in the following error message:
    « MODx Parse Error »
    MODx encountered the following error while attempting to parse the requested resource:
    « Execution of a query to the database failed - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '[*phx:inpu) AND sc.published=1 AND sc.deleted=0) AND (sc.privat' at line 3 »
          SQL: SELECT DISTINCT sc.id FROM `smartspacedb`.`modx_site_content` sc LEFT JOIN `smartspacedb`.`modx_document_groups` dg on dg.document = sc.id WHERE (sc.id IN ([*phx:inpu) AND sc.published=1 AND sc.deleted=0) AND (sc.privateweb=0) GROUP BY sc.id 



    At first i thought it was my syntax of the PHx statement but then just for the test i tried a simple PHx modifier like so:
    [[Ditto?&documents=`[*phx:input=`[*optionsTempRoof*]`:math=`?+1-1`*]`&phx=`0`&tpl=`@FILE:assets/chunks/templates/product_option_related_tpl.chk`]]


    and got this error:

    « MODx Parse Error »
    MODx encountered the following error while attempting to parse the requested resource:
    « Execution of a query to the database failed - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '[*phx:inpu) AND sc.published=1 AND sc.deleted=0) AND (sc.privat' at line 3 »
          SQL: SELECT DISTINCT sc.id FROM `smartspacedb`.`modx_site_content` sc LEFT JOIN `smartspacedb`.`modx_document_groups` dg on dg.document = sc.id WHERE (sc.id IN ([*phx:inpu) AND sc.published=1 AND sc.deleted=0) AND (sc.privateweb=0) GROUP BY sc.id 



    Which tells me that PHx is not getting parsed inside Ditto. Running the same PHx statement by itself returns the the correct document id.

    Any suggestions will be greatly appreciated.

    Thanks in advance.




      • 16278
      • 928 Posts
      PHx is not getting parsed inside Ditto
      Surely Ditto will only parse PHx in the tpl chunks, not in the Ditto call?

      Perhaps a wrapper snippet would solve your problem, passing the value of the TV to it as a parameter.
      smiley KP
        • 22448
        • 241 Posts
        Does this apply to all snippets?
        At what point do PHx statements actually get parsed?
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          The internal Ditto phx class only works on Ditto tpls. For any PHx processing other than that, you need to have the PHx plugin installed. The plugin code is executed (processing any phx placeholders) before any other MODx tags are processed.
            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
            • 22448
            • 241 Posts
            Hi Susan,

            actually I just finished going through your tutorials. Great stuff.

            That’s what i thought about PHx, but it doesn’t work. As you can see in the second example above I’ve tried turning Ditto PHx off (&phx=`0`) and use PHx syntax with &input=`...`. But it still results in error. If i run the same PHx statement by itself everything works just fine.

            I’m beginning to think that the issue is with the configuration somewhere.
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              Have you tried various combinations of cached/uncached snippet call/page?
                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