add() public method

### Example: $templater->add([ 'link' => '{{title}}' 'button' => '' ]);
public add ( array $templates )
$templates array An associative list of named templates.
 /**
  * templater
  *
  * @return \Cake\View\StringTemplate
  */
 public function templater()
 {
     if (empty($this->_templater)) {
         $class = $this->config('templateClass') ?: 'Cake\\View\\StringTemplate';
         $this->_templater = new $class();
         $templates = $this->config('templates');
         if ($templates) {
             if (is_string($templates)) {
                 $this->_templater->add($this->_defaultConfig['templates']);
                 $this->_templater->load($templates);
             } else {
                 $this->_templater->add($templates);
             }
         }
     }
     return $this->_templater;
 }
Esempio n. 2
0
 /**
  * Ensure templateVars option is hooked up.
  *
  * @return void
  */
 public function testRenderTemplateVars()
 {
     $this->templates->add(['button' => '<button {{attrs}} custom="{{custom}}">{{text}}</button>']);
     $button = new ButtonWidget($this->templates);
     $data = ['templateVars' => ['custom' => 'value'], 'text' => 'Go'];
     $result = $button->render($data, $this->context);
     $expected = ['button' => ['type' => 'submit', 'custom' => 'value', 'class' => 'btn btn-default'], 'Go', '/button'];
     $this->assertHtml($expected, $result);
 }