Saving all templates to files quickly in ExpressionEngine
Ok, lets just put this on the table, I absolutely hate the ExpressionEngine template editor. I fully understand why it is there and it can come in handy in very rare circumstances, but I'm always surprised when I see a large site not saving templates as files. I am working on a site right now that has over 600 templates and over 350 custom fields. The client is high profile and has significant traffic so in the midst of doing a lot of clean up and re-organizing, I'm also having to do many maintenance and template updates. They were extremely pleased with the fact that we have cut most of the maintenance and template update time in half by being able to access actual files and not having to click around in the template manager.
So, if you need to quickly save all of your templates as files and have access to the database, here's what you do:
-
BACK UP YOUR DATABASE!!
-
Set your Global Template preferences to allow you to save templates as files ( Design > Templates > Global Preferences )
-
Run this query:
UPDATE exp_templates SET `save_template_file` = 'y';
You can always throw a WHERE statement in there if you want to limit by site (WHERE `site_id` = x) or template group (WHERE `group_id` = x).
- Navigate to Design > Templates > Synchronize Templates and all of your database templates should now be in your template location as specified in Global Preferences.
One last note, I have noticed some inconsistencies within EE as to when the flat files sync with the database. It seems like some do it when you visit the template manager and some do it when you actually save and upload the file, but I haven't nailed down an exact version number.