We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 42639
    • 9 Posts
    I'm creating a tv which will allow me to select from a listbox any of the pages on my site that use a specific template. I'll be using this tv on Articles blog posts to power 'related news' type functionality elsewhere on the site. To be more specific, the site is a directory of motor racing circuits and I want to be able to link news stories with the relevant circuit page and vice versa.

    I can quite successfully create my list using the following Input Option Values:
    @SELECT pagetitle, id FROM modx_site_content WHERE template = 17 ORDER BY pagetitle ASC


    However, it would be useful to have a first item in the list which was blank, rather than it always being the first actual page alphabetically. This is because there are some news items which will be about circuits that do not yet have a page elsewhere on the site and, currently, it is impossible to deselect an item from the list once it has initially been chosen and saved, even if in error.

    I believe it might be possible to modify my Input Option Value to have to @SELECT values with a UNION to join them together, but that's about as far as I have got. Does anyone have any ideas? It does seem to be a bit of missing functionality within the listbox that would be much appreciated in future versions!

    This question has been answered by multiple community members. See the first response.

    • discuss.answer
      • 44580
      • 189 Posts
      This should work (not tested):
      @select "-Make selection-", "" from dual
      union
      (SELECT pagetitle, id FROM modx_site_content WHERE template = 17 ORDER BY pagetitle ASC)
        • 42639
        • 9 Posts
        Quote from: gissirob at Jan 10, 2015, 06:12 AM
        This should work (not tested):
        @select "-Make selection-", "" from dual
        union
        (SELECT pagetitle, id FROM modx_site_content WHERE template = 17 ORDER BY pagetitle ASC)

        Works a treat - many thanks!
          • 42639
          • 9 Posts
          Quote from: gissirob at Jan 10, 2015, 06:12 AM
          This should work (not tested):
          @select "-Make selection-", "" from dual
          union
          (SELECT pagetitle, id FROM modx_site_content WHERE template = 17 ORDER BY pagetitle ASC)

          Just a thought - can I exclude any weblinks that use the same template?
            • 44580
            • 189 Posts
            Yes, if you know how to identify weblinks in the table (I assume it is the type column but I don't have an example to hand). If it is, then this should work:
            @select "-Make selection-", "" from dual
            union
            (SELECT pagetitle, id 
            FROM modx_site_content 
            WHERE template = 17 
            AND id not in (select id from modx_site_content where type = 'weblink' and template = 17)
            ORDER BY pagetitle ASC)

            If not, you get the drift...
            • discuss.answer
              • 44580
              • 189 Posts
              If the above doesn't work, then try this:
              AND id not in (select id from modx_site_content where class_key = 'modWebLink' and template = 17)

                • 42639
                • 9 Posts
                Quote from: gissirob at Jan 11, 2015, 06:10 PM
                If the above doesn't work, then try this:
                AND id not in (select id from modx_site_content where class_key = 'modWebLink' and template = 17)


                Yeah, it's the latter! Thanks as ever.
                  • 44580
                  • 189 Posts
                  I never was good at guessing. It helps when you actually look it up! smiley