ProcessWire
Recipes_

Field/template context

Problem

Fields can have template-contextual settings and as of ProcessWire 2.5.7 you can set all field settings in a template context. Using the API it works a bit differently than the usual $f->set('setting', $value); $f->save();.

Solution

// get the template
$t = $templates->get('basic-page');

// get the field in context of this template
$f = $t->fieldgroup->getField('summary', $useFieldgroupContext = true);

// value of the field
$f->description = "Description of 'summary' only in context of 'basic-page'";

// save new setting in context
$fields->saveFieldgroupContext($f, $t->fieldgroup);

Resources