$templatesnewTemplate()

Create new template in memory

Available since version 3.0.258.

Example

// Simple usage
$template = $templates->newTemplate('product');
$template->label = 'Product item';
$template->save();

// Example of specifying settings
$template = $templates->newTemplate('product', [
  'label' => 'Product item',
  'fields' => [ 'title', 'body', 'price' ],
]);
$template->save();

Usage

// basic usage
$template = $templates->newTemplate($name);

// usage with all arguments
$template = $templates->newTemplate($name, $settings = []);

Arguments

NameType(s)Description
$namestring array

Name of template or array of settings that includes 'name', and anything else that would usually go in $settings array.

$settings (optional)array string

Array of settings to set, or string for template label only Use any template setting/property or fields array containing names of fields to add.

Return value

Exceptions

Method can throw exceptions on error:

  • WireException - If given a template name that already exists


$templates methods and properties

API reference based on ProcessWire core version 3.0.265