We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 7378
    • 3 Posts
    Hi, I would like to obtain information about the current page via ditto. The ditto call I am attempting is:

    [[Ditto? &documents=`[*id*]` &tpl=`BlogInfo` &dateFormat=`%A %e %B %Y` &tagData=`documentTags` &tagDelimiter=`,` ]]


    When I type a specific id instead of "[*id*]" it gives the result I want. However, this is returning an error message when I attempt to view the page with the above ditto call:

    « 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 ’[*id*]) AND sc.published=1 AND sc.deleted=0) AND (sc.privatewe’ at line 3 »
    SQL: SELECT DISTINCT sc.id FROM `schema`.`modx_site_content` sc LEFT JOIN `schema`.`modx_document_groups` dg on dg.document = sc.id WHERE (sc.id IN ([*id*]) AND sc.published=1 AND sc.deleted=0) AND (sc.privateweb=0) GROUP BY sc.id
    [Copy SQL to ClipBoard]

    Parser timing
    MySQL: 0.0017 s (11 Requests)
    PHP: 0.0665 s
    Total: 0.0681 s

    Obviously the [*id*] is not being substituted in the snippet call which I thought was possible. The question is how to I restrict the Ditto result to the current page.
      • 4749
      • 623 Posts
      Is it my inexperience or do you have to specify &parents ? Or does it default to [*parents*]?
        The MODx has you...
        Utah Web Design
        • 7378
        • 3 Posts
        The "parents" parameter does not seem to be needed when "documents" is used. For example the following gives me the result I want:

        [[Ditto? &documents=`47` &tpl=`BlogInfo` &dateFormat=`%A %e %B %Y` &tagData=`documentTags` &tagDelimiter=`,` ]]
          • 7231
          • 4,205 Posts
          This sounds like a parser pass issue. Try it with un-cached tags [!Ditto?..!].

          You may enjoy reading this recent article on the parser, it helps understand why some conflicts happen.
            [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

            Something is happening here, but you don't know what it is.
            Do you, Mr. Jones? - [bob dylan]
            • 7378
            • 3 Posts
            Thank-you. Your suggestion worked. However, I was using the [[ ]] style purposely because I was using the following snippet to dynamically include the BlogHeader chunk (the ditto call from my previous post) if the page had a template variable "blogPageIndicator" set (gets set whenever a blog is created):

            [!ConditionalContent? &isIncluded=`[*blogPageIndicator*]` &contentTpl=`BlogHeader` !]


            ConditionalContent snippet
            <?php
            /*
             * Description
             *     Output content if included flag is set.
             * Parameters
             *     &isIncluded - set to 1 to include, 0 to exclude.
             *     &isExcluded - set to 1 to exclude, 0 to include.
             *     &contentTpl - the content chunk to include if it is included.
             * Notes:
             *     This uses evalSnippets (see http://modxcms.com/forums/index.php?topic=22914.0)
            */
            if ($isIncluded == '1' || $isExcluded == '0') {
              return $modx->evalSnippets($modx->getChunk($contentTpl));
            }
            ?>


            On rethinking the solution I have created a purpose specific snippet that works correctly:

            [!OnlyForBlogPageHeader? &isBlogPage=`[*blogPageIndicator*]`  !]


            OnlyForBlogPageHeader snippet
            <?php
            /*
             * Description
             *     Output content if blog flag is set.
             * Parameters
             *     &isBlogPage- set to 1 to include, 0 to exclude.
            */
            if ($isBlogPage == '1') {
              $params = array();
              $params['documents'] = $modx->documentIdentifier;
              $params['tpl'] = 'BlogInfo';
              $params['dateFormat'] = '%A %e %B %Y';
              $params['tagData'] = 'documentTags';
              $params['tagDelimiter'] = ',';
              echo $modx->runSnippet('Ditto', $params);
            }
            ?>


            Why did I do this? Because I wanted to ’decorate’ the blog page.

            I could have used the chunk {{BlogHeader}} directly in the blog page content and then the Ditto "removeChunk" parameter. However, this requires that each existing blog page have the BlogHeader chunk inserted. My thinking at the time was when the site matured I did not want to have to modify every blog page for future additions. Now I realise that two chunks would probably work as well - BlogHeader and BlogFooter.

            The ’decorater’ solution allows the template to dictate different header/footer chunks, so there is more flexibility. So it probably depends on how much flexibilty in displaying the blog pages is required.

            Another solution would be to have two templates - almost identical, one for blog pages, one for the main site. I am somewhat averse to the duplication though smiley