We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 727
    • 502 Posts
    I’m evaluating MODx to see if it is suitable for my needs. I’ve figured out how to add template variables, but what I want to do now (from a snippet) is to access all the values for a specific template variable in the site.

    For example:

    I have a template called "location" and it has a template variable called "type". Type can be "outside" or "inside". In a snippet I know how to get the type of the current document, but how do I get the types of all the documents in the site which are based on the location template?

    Is this possible?

    thanks!, Andy
    • Garry Nutting Reply #2, 18 years ago
      Hi ajayre,

      Of course it can be done, it’s MODx grin

      You’ll need to do a SQL query that left joins the template variable content table to the site content table.

      Here’s the example query (you’ll need to change the table prefix, tmplvarid value, and template id value to your desired values - check in your database tables what these need to be set to) and I’m just returning the content ID and template variable content, but you could tweak this to your needs.

      SELECT `modx_site_content`.id, value
      FROM `modx_site_tmplvar_contentvalues`
      LEFT JOIN `modx_site_content` ON `modx_site_tmplvar_contentvalues`.contentid = `modx_site_content`.id
      WHERE `modx_site_tmplvar_contentvalues`.tmplvarid =4
      AND `modx_site_content`.template =6


      Of course, you can use the MODx API to run this query, but I thought just showing the straight query might be better. If you need help with the code, then just post back.

      Hope that helps, Garry
        Garry Nutting
        Senior Developer
        MODX, LLC

        Email: [email protected]
        Twitter: @garryn
        Web: modx.com
        • 727
        • 502 Posts
        Thanks Garry! Seems that MODx has all the features/flexibility I need, which is great. smiley

        Andy