We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 20232
    • 4 Posts
    Hi,

    I thought I’d share since this took me a while to figure out how to do and it turned out easy in the end.

    To create a drop down template variable with options like
    <option value="id of the modx doc"> (id of modx doc) Page Title</option>
    (Note the inclusion on the id in round brackets is simply because there are frequently documents with the same pagetitle in a site.)

    Create a TV with

    • Variable Name: docLink
    • Input Type: Drop Down List Menu
    • Input Option Values: @SELECT CONCAT(’(’,id,’)’,pagetitle) AS Column1,id FROM modx_site_content ORDER BY pagetitle, id

    Then in your templates, or chunks simply use href="[~docLink~]"

    Morgy
      • 5340
      • 1,624 Posts
      Nice CONCAT trick.
      I hope my neurons will remember smiley
        • 26982
        • 75 Posts
        Just a correction, you should link using [~[*docLink*]~]

        Cheers,

        /\dam
          • 4080
          • 139 Posts
          This is super cool but I’m having trouble getting it to work. Is this code for Revo? I’m running 1.0.4 and I’m getting a parse error when editing a resource (see attached screenshot). I’m still a bit new to MODx here so it’s probably something I’m doing (or not doing). Any help is greatly appreciated!

            • 25195
            • 9 Posts
            Hi,

            did you install with a table prefix different from the default modx_ ?
            if yes then update the sql below with the prefix you used instead of modx_
            @SELECT CONCAT('(',id,')',pagetitle) AS Column1,id FROM [Your_DB_Prefix]site_content ORDER BY pagetitle, id


            I’ve just been looking at the MODx docs and (at)SELECT suggests you can use [+prefix+] in the sql but trying that I get
            « 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 ’[+prefix+]site_content ORDER BY pagetitle, id’ at line 1 »
            SQL: SELECT CONCAT(’(’,id,’)’,pagetitle) AS Column1,id FROM [+prefix+]site_content ORDER BY pagetitle, id;

            I guess I’ve missed somehing obvious, but I can’t work out what.

            Regards
            Keith
              • 4080
              • 139 Posts
              Thank you for the suggestion! This particular site is on Bluehost which offers the automated install of MODx. I wonder if the table prefix is different doing this way? I’ll have to log in and check it out. Thanks again!
                • 25195
                • 9 Posts
                Hi,

                I’ve worked it out now, I nearly got it right, just the [+prefix+] needs to be [+PREFIX+] so change the code to:
                @SELECT CONCAT('(',id,')',pagetitle) AS Column1,id FROM [+PREFIX+]site_content ORDER BY pagetitle, id

                and it should work for you.

                Regards
                Keith
                  • 4080
                  • 139 Posts
                  That did it! Thanks, Keith. Great tool to add to the toolkit. Any idea how to sort it by indenting (like the sorted link list in TinyMCE) or set a depth limit? I’m not savvy enough to try but thought I’d ask. Super useful either way. Thanks again!
                    • 4080
                    • 139 Posts
                    I tweaked it ever so slightly to order by resource ID and added a space after the (#). This is great for small sites in particular. Does anyone know if someone’s developed a way to do this up the same as how the cool little icon works when selecting a Weblink resource’s URL? I’m guessing that’s a core hack, custom plugin or module? That’s smarty pants stuff.
                    @SELECT CONCAT('(',id,')  ',pagetitle) AS Column1,id FROM [+PREFIX+]site_content ORDER BY id


                    Thanks once again for this super handy trick!

                    UPDATED BELOW:

                    I tweaked a little further (I BARELY know anything about SQL statements) and came up with a resource list that’s simply alphabetical since the resource ID# doesn’t always mean something to the end user:
                    @SELECT (pagetitle) AS Column1,id FROM [+PREFIX+]site_content ORDER BY pagetitle
                      • 29201
                      • 239 Posts
                      thanks morgycat and brian! this is rad.

                      i have to wonder if this isn’t part of Revo out of the box because it is so handy!

                      Cheers and thanks again guys!