GuruMeditation Posted November 9, 2014 Posted November 9, 2014 Hi, I'm trying to create a template for a module I'm working on. The page that uses this template will be used specifically as a category to hold other pages. For this reason, I don't need to add any extra fields to it, other than the title, and obviously the name. But I can't seem to figure out how to do it. I've tried the following, but it complains about needing a field. $template_category = new Template(); $template_category->name = 'template_category'; $template_category = $template_category->save(); Any help appreciated.
kongondo Posted November 9, 2014 Posted November 9, 2014 Templates need corresponding fieldgroups...Something like below should do it (not tested, written quickly!) //new fieldgroup $fg = new Fieldgroup(); $fg->name = 'template-category'; $fg->add(wire('fields')->get('title')); $fg->save();//save the fieldgroup //create a new template to use with this fieldgroup $template_category = new Template(); $template_category->name = 'template-category'; $template_category->fieldgroup = $fg; //add the fieldgroup we created above $template_category->label = 'Category Template'; //template label $template_category->save(); 4
Raymond Geerts Posted November 9, 2014 Posted November 9, 2014 kogondo was a little faster, anyway also not tested, just grabbed from a module i was working on. This also includes the creation of the page containing the template. $fieldgroup_category = new Fieldgroup(); $fieldgroup_category->name = 'template_category'; $fieldgroup_category->add($this->fields->get('title')); $fieldgroup_category->save(); $template_category = new Template(); $template_category->name = 'template_category'; $template_category->fieldgroup = $fieldgroup_category; $template_category->noChildren = 0; $template_category->noParents = 0; $template_category->slashUrls = 1; $template_category->urlSegments = 0; $template_category->pageLabelField = 'title'; $template_category->save(); $page_category = new Page(); $page_category->template = $template_category; $page_category->parent = 1; $page_category->title = 'Category'; $page_category->name = 'category'; $page_category->process = $this; $page_category->save(); 3
GuruMeditation Posted November 10, 2014 Author Posted November 10, 2014 Thanks lads, that works a treat.
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