Exemple #1
0
 public function testCustomPatternData()
 {
     $primer = Primer::start(array('basePath' => __DIR__ . '/primer-test', 'templateClass' => HandlebarsTemplateEngine::class));
     $pattern = new Pattern('components/patterns/custom-data', ['name' => 'Test name']);
     $output = $pattern->render(false);
     $this->assertEquals("Test name", $output);
 }
Exemple #2
0
 /**
  * Get a specific page template
  *
  * @param  String $id The template id
  * @return String
  */
 public function getTemplate($id)
 {
     // Default system wide template wrapping config
     $wrapTemplate = Primer::$WRAP_TEMPLATES;
     $id = Primer::cleanId($id);
     // Create the template
     $template = new Pattern('templates/' . $id);
     $templateData = new ViewData(["primer" => ['bodyClass' => 'is-template', 'template' => $id]]);
     $data = $template->getData();
     // Template level wrapping config
     if (isset($data->primer->wrapTemplate)) {
         $wrapTemplate = $data->primer->wrapTemplate;
     }
     if ($wrapTemplate) {
         $view = 'template';
         // Check the data to see if there is a custom view
         if (isset($data->primer) && isset($data->primer->view)) {
             $view = $data->primer->view;
         }
         $templateData->primer->items = $template->render(false);
         Event::fire('render', $templateData);
         return View::render($view, $templateData);
     } else {
         // Merge the data we would have passed into the view into the template
         $template->setData($templateData);
         // Get a reference to the template data so that we can pass it to anyone who's listening
         $viewData = $template->getData();
         Event::fire('render', $viewData);
         return $template->render(false);
     }
 }