Jump to content

Module to create templates


tires
 Share

Recommended Posts

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!

 

Link to comment
Share on other sites

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.

  • Like 2
Link to comment
Share on other sites

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.

  • Like 1
Link to comment
Share on other sites

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.

  • Like 2
Link to comment
Share on other sites

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. :)

  • 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
 Share

×
×
  • Create New...