We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 24189
    • 19 Posts
    Hi ModX’ers

    I am stuck on this.
    I have a TV that generates a (select-)list of documents from a folder.
    To achieve this, I have an @SELECT in the TV:
    @SELECT pagetitle,id FROM [+PREFIX+]site_content WHERE parent=999


    This works fine.

    Now, I am working on a multiple language site and I want to get the parent-folder-id dynamically, so I can use the same TV on either language.
    This means that I need to find a way to have something like this:
    @SELECT pagetitle,id FROM [+PREFIX+]site_content WHERE parent=[ID-DEPENDING-ON-LANGUAGE]


    I seem not to get the solution and somehow I fear that there is none sad
    In that case, I would have to add a (site)template for each language an assign the language-based TV’s to the according template.

    I hope that someone has a solution for this...

    Thanks for your replies.

    QT
      • 22303 MODX Staff
      • 10,725 Posts
      Simply create a Snippet to do the query and return those results, or use @EVAL to execute the PHP to do so using the MODx DBAPI.
        • 24189
        • 19 Posts
        Hi OpenGeek

        Thank you for your reply.

        Actually I already did try the *snippet* variation. But without any luck so far.

        This is what I have done:
        Snippet: MakeSQLquery
        The return value of that Snippet is (test on page successful):
        @SELECT pagetitle,id FROM modx_site_content WHERE parent=999


        When I call the same snippet from another language page I get the right parent_id.
        So far so good.

        Now, I put the following code into my TV (Input Option Values):
        @EVAL return $modx->runSnippet('MakeSQLquery');


        When I open an admin page with that TV assigned, I get a "Cannot modify header information - headers already sent by..." system error.

        What am I missing?

        Can you help?

        Thanks a lot in advance!

        QT
          • 22303 MODX Staff
          • 10,725 Posts
          Just write the snippet to return the results you want, not to write out the @SELECT statement, though if that’s what you want to do, why not just put [[MakeSQLQuery]] in the TV? No need to @EVAL a snippet which is also being eval()’d.
            • 24189
            • 19 Posts
            Hi OpenGeek

            Thanks again.

            As of further research I figured out that the problem was lying elsewhere.

            The TV (let’s call it ’tvDynamicSelect’) has to work in the admin only.
            That means, that the relation to the parent folders has to be established in the content manager only.
            It did not occur to me in the first place, that I could not use the $modx-document-functions to get e.f. the documentIdentifier of the page that is being edited.
            So where to get that id?
            Of course => $_GET[id]

            Form here it was easy to get the data.
            Now it works perfectly fine.

            Sometimes it’s obvious, but not to me.... sad

            Thanks for your input again.

            Cheers!
            QT