Package Controller, Page Templates...and Page Types

Permalink
Okay so I took a page from this how-to on reliable package installation and updates:https://www.concrete5.org/documentation/how-tos/developers/reliable-... which worked well for c5 5.6 and below.

I've managed to get things working well with everything except page templates.

Adding each template individually works fine like this:
if (!is_object(PageTemplate::getByHandle('right_sidebar'))){
            $pt = PageTemplate::add('right_sidebar', 'Right Sidebar');
          }

Running the code with an array doesn't seem to work, OR I am going about it all wrong, which is what I hope is the case.

My public function looks like this:
protected $pagetemplates = array(
          'complex'=>'Complex',
          'right_sidebar'=>'Right Sidebar',
          'left_sidebar'=>'Left Sidebar',
          'full'=>'Full'
        );
      // add page types from array
        public function configurePageTemplates($pkg) {
          foreach($this->pagetemplates as $key => $pagetemplates) {
            $pt = PageTemplate::getByHandle($key);
            if(!is_object($pt)) {
              $data['pTemplateHandle'] = $key;
              $data['pPageTemplateName'] = t($pagetemplates);
              $pt = PageTemplate::add($data,$pkg);
            }


This get me an error of: Object of class Concrete\Package\My_Theme\Controller could not be converted to string. Using the old method with Collection Type is a whole other error.

Any thoughts?

justrj
 
hutman replied on at Permalink Best Answer Reply
hutman
If I'm seeing this right you need to change your setup just a little to get this to work

if(!is_object($pt)) {
     $pt = PageTemplate::add($key, t($pagetemplates), FILENAME_PAGE_TEMPLATE_DEFAULT_ICON, $pkg)
}


Here is the reference I used to come up with this: http://concrete5.org/api/class-Concrete.Core.Page.Template.html...
justrj replied on at Permalink Reply
justrj
Thank you so much!

I was so obsessed with making sure that I had the right class names that I missed that. ..couldn't see the forest for the trees.