tires Posted February 7, 2017 Posted February 7, 2017 Hi! I tried to crate a little module that creates me a few template ... but without success so far. I have an array with a few template-names. I walk througt the array to create the templates. The module doesnt work porperly. And i havent find out how to add fields to the templates (at least a title field)? Here is my code: <?php class maketemplate extends WireData implements Module { public static function getModuleInfo() { return array( 'title' => 'maketemplate', 'version' => 1, 'summary' => 'Creates templates', 'author' => 'Me', 'singular' => true, 'autoload' => true, 'icon' => 'diamond' ); } public function ___install() { $array1 = array("mytemplate1", "mytemplate2","mytemplate3"); foreach($array1 as $templ) { $t = new Template(); $t->name = $templ; $t->save(); } $this->message("Template created"); } } ?> Or is there already a module that can do this job? Cheers!
tpr Posted February 7, 2017 Posted February 7, 2017 You could just use Tracy Debugger's Console Panel to create templates. I often use it for creating fields and assign to templates. 2
adrian Posted February 7, 2017 Posted February 7, 2017 @tires - this could actually be a nice AdminActions action. I would use the "Template Fields Batcher" action as a starting point as it will show you how to add fields to templates. If you like this idea and have a go at building an action, please let me know if you need any help. 1
kongondo Posted February 7, 2017 Posted February 7, 2017 Templates need to be coupled to fieldgroups (which need to be created first). I see that your module is an autoload module...was that intentional? Anyway, what the others said. If you need to look at a complete example, here's some code from the Blog module installer. 2
Robin S Posted February 7, 2017 Posted February 7, 2017 FYI, you can add multiple templates in one go via the admin interface: 4
adrian Posted February 7, 2017 Posted February 7, 2017 2 minutes ago, Robin S said: FYI, you can add multiple templates in one go via the admin interface: Nice one - I totally forgot about this 1
Robin S Posted February 7, 2017 Posted February 7, 2017 2 minutes ago, adrian said: I totally forgot about this I get the feeling this feature is rarely used. I'd like to see it dropped in favour of not being booted back to Setup > Templates after creating a new template, and then having to reopen the settings for the template you just created to add a label, fields, etc. I find that much more a hindrance than I would not being able to create multiple empty templates. 1
cstevensjr Posted February 7, 2017 Posted February 7, 2017 15 minutes ago, Robin S said: I get the feeling this feature is rarely used. I'd like to see it dropped in favour of not being booted back to Setup > Templates after creating a new template, and then having to reopen the settings for the template you just created to add a label, fields, etc. I find that much more a hindrance than I would not being able to create multiple empty templates. Maybe rarely used by some, however I make use of it. There are many ways to do many things in ProcessWire, i would hate to lose any functionality or convenience. My two cents on this issue. 2
Robin S Posted February 7, 2017 Posted February 7, 2017 1 minute ago, cstevensjr said: Maybe rarely used by some, however I make use of it. There are many ways to do many things in ProcessWire, i would hate to lose any functionality or convenience. My two cents on this issue. Sure, losing functionality is not good. Elsewhere I proposed a separate button for the cases where you want to add multiple templates. However, in terms of the total amount of convenience for the total number of users, I think the times you want to add fields and other settings immediately after adding a new template much outnumbers the times you want to add multiple empty templates and then end up back at Setup > Templates. 3
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now