2

is there a way to add a field to a global set by code ? I figured out how to create a global:

$global = new GlobalSetModel();
$global->name = 'GlobalName';
$global->handle = 'globalHandle';
craft()->globals->saveSet($global)

But I can't figure out how to add a field to this newly create global.

1

See here for how to add a field to a user's field layout.

Users, Globals, Tags, Categories, etc. are all elements in Craft so they behave very similarly.

You can also check out Craft's own InstallService's private _createDefaultContent() method for examples on how Craft creates the default content on a fresh install of Craft.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.