phalcon - Macros accessible everywhere -


i trying create macro templates this:

{%- macro bfield(form, name, attributes) %}     <p class="form-group" ng-class="{has-error: !{{ form.name }}.{{ name }}.$valid}">         {{ form.label(name) }}         {#{% set attributes['class'] = 'form-control' %}#}         {{ form.render(name, attributes) }}         {% include 'forms/validation-messages.volt' %}     </p> {%- endmacro %} 

the issue is in macros.volt file in views root , dont have idea how or include available everywhere. tried in root layout (index.volt) include , partial functions still doesnt work. not in template file trying use in. doing wrong, how fix this?

another thing how set value on key in array. tried {% set attributes['class'] = 'form-control' %}, doesnt work.

awesome solution, found on phalcon forums. customized little situation.

suggestion extend volt engine class , load each macro file during \phalcon\mvc\view\engine\volt::getcompiler.

// extended class load macros before parse time class voltc extends \phalcon\mvc\view\engine\volt {     public function getcompiler()     {       if (empty($this->_compiler))       {         parent::getcompiler();          // add macros need initialized before parse time         $this->partial("macros/form");       }        return parent::getcompiler();     } } $di->set("voltengine", function( $view, $di ){     $volt = new voltc($view, $di);      $volt->setoptions(array(         "compiledpath" => "../app/tmp/cache/",         "compiledextension" => ".cmp",         'compilealways' => true     ));      return $volt; }); 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -