Example #1
0
 /**
  * Load controller and view
  * @param  string $template Template
  * @return mixed            Exception or false, false to make sure no
  *                          standard template file from wordpres is beeing included
  */
 public function load($template)
 {
     if (!empty(get_page_template_slug()) && get_page_template_slug() != $template) {
         if (file_exists(get_page_template_slug())) {
             $template = get_page_template_slug();
         }
     }
     if (!\Municipio\Helper\Template::isBlade($template)) {
         $path = get_template_directory() . '/' . $template;
         // Return path if file exists, else default to page.blade.php
         if (file_exists($path)) {
             return $path;
         } else {
             if (current_user_can('administrator')) {
                 \Municipio\Helper\Notice::add('<strong>' . __('Admin notice', 'municipio') . ':</strong> ' . sprintf(__('View [%s] was not found. Defaulting to [page.blade.php].', 'municipio'), $template), 'warning', 'pricon pricon-notice-warning');
             }
             $template = \Municipio\Helper\Template::locateTemplate('views/page.blade.php');
         }
     }
     // Clean the view path
     $view = $this->cleanViewPath($template);
     // Load view controller
     $controller = $this->loadController($view);
     // Render the view
     $data = null;
     if ($controller) {
         $data = $controller->getData();
     }
     $this->render($view, $data);
     return false;
 }