Jump to content

Dynamically Create Template

Brian Scramlin

Recommended Posts



namespace ProcessWire;

// create field
$field = new Field();
$field->name = 'my_field';
$field->label = 'My Field';
$field->type = 'FieldtypeText';

// save field
// get field
$field = wire('fields')->get('my_field');

// Create fieldgroup
$fieldgroup = new Fieldgroup();
// if you want to edit fields in this field group via admin panel, name need to be same with template name
$fieldgroup->name = 'my_template';

// save fieldgroup
// get fieldgroup
$fieldgroup = wire('fieldgroups')->get('my_template');

// Create template
$template = new Template();
$template->name = 'my_template';
$template->label = 'My Template';
$template->fieldgroup = $fieldgroup;

// save template
// get template
$template = wire('templates')->get('my_template');


  • Like 3
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

  • Recently Browsing   0 members

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