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

    I sincerely hope this is not an ’ask-and-answered 100 times’ type question, because I’ve been searching for the solution for a while. Is there a fast and efficient way to assign a large amount of template variables to a newly created template?

    We have about 30 TVs, many of which are needed for every page on our site. This means a lot of manual work every time we create a new Template. It seems like there has to be a faster way. Can anyone point me in a better direction?

    Thanks for the help,

    Daniel Hirsch
      • 23491 ☆ A M B ☆
      • 1,056 Posts
      Quote from: dhirsch at Nov 03, 2008, 01:10 PM

      Hello everyone,

      I sincerely hope this is not an ’ask-and-answered 100 times’ type question, because I’ve been searching for the solution for a while. Is there a fast and efficient way to assign a large amount of template variables to a newly created template?

      We have about 30 TVs, many of which are needed for every page on our site. This means a lot of manual work every time we create a new Template. It seems like there has to be a faster way. Can anyone point me in a better direction?

      Thanks for the help,

      Daniel Hirsch

      Daniel,

      Depending on your familiarity of the MODx schema and SQL knowledge, you can pretty easily create SQL to handle the necessary TV mappings for a given template. You just need to to associate the given Template Variable IDs with the corresponding templates, only in bulk and no GUI required smiley

      Example:
      
      insert ignore into modx_site_tmplvar_templates ( tmplvarid, templateid )
      select
      	tmplvarid, 3 as new_template
      from
      	modx_site_tmplvar_templates
      where
      	templateid in ( 6 )
      


      The following SQL will associate all TVs from Template ID: 6 to Template ID: 3...

      NOTE: The IGNORE flag will prevent dupe-key errors in the event the TV is already mapped to the new template, in other words mapping only those TVs that need to be mapped.

      Should you want to filter on the TVs being imported, simply alter the WHERE clause to include a " AND tmplvarid NOT IN ( ... )"

      Hope that helps!

      Mike
        Mike Reid - www.pixelchutes.com
        MODx Ambassador / Contributor
        [Module] MultiMedia Manager / [Module] SiteSearch / [Snippet] DocPassword / [Plugin] EditArea / We support FoxyCart
        ________________________________
        Where every pixel matters.