Jump to content

Is it possible to migrate/import/export fields and templates for reuse?


tinacious
 Share

Recommended Posts

Hello. I find that when I make new ProcessWire sites I am often re-creating similar fields and templates. Is it possible to export/import/reuse this "setup" easily? I don't want the content just the fields and templates. Is this possible? I guess I'm looking for a solution similar to Drupal's Features export. Thanks for your help.

Link to comment
Share on other sites

  • 4 weeks later...
  • 7 months later...

I'm in the process of building a complicated module and was thinking that being able to create the fields in the admin quickly, then export as a JSON string to use in the installer function would be much quicker than what I'm faced with at the moment - manually typing out the code for all the fields I need to add is taking a long time, so aside from the uses when copying fields/templates to other PW installations it would be fantastic to be able to generate the JSON and in a module's installer just do something like this if we wanted to change some template details or add some additional fields:

$templatedata = json_decode($jsonstring);
$fieldgroup = new Fieldgroup($templatedata->fields);
$template = new Template();
$template->name = "template-name";
$template->fieldgroup = $fieldgroup;
$template->save();

Or if we were happy with the template name we'd exported and all the fields, then this:

// Adding template "template name"
$templatedata = json_decode($jsonstring);
$template = new Template($templatedata); // $templatedata contains template and field information
$template->save();

The second option means you won't even know what the template is called unless you know how to read a JSON string, but I like its simplicity, and we can just put a comment above it as in my example :)

Just a thought.

  • Like 3
Link to comment
Share on other sites

I agree, I think export/import methods like this on Fields and templates would be nice. There's a lot of considerations though, especially on import. Like whether individual fields already exist or not, whether those field definitions reference external things (like page IDs). That's not to say it isn't doable, but just that there is potential for it to get quite a bit more complex than it first appears. But I would like to implement some API level expor/import functions for this soon, to at least get things moving forward. I've already been working on similar export/import functions for Page objects (which you see in the latest dev branch, though they aren't yet active). 

  • Like 7
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...