CSS for Symfony2 forms: "Hello World" equivalent -


how alter fields.html.twig template? looking "hello world" equivalent see first ever change form.

what's working (within bundle view add.article.html.twig):

         <div class="well;">               <form method="post" {{ form_enctype(form) }}>                  {{ form_widget(form,{attr: {class:'test'}} ) }}                  <input type="submit" class="btn btn-primary" />               </form>          </div> 

the test class doing css .test{background-color:grey;}. using bootstrap.


in fields.html.twig have:

    {% block aliquam_input %}     {% spaceless %}       <div>         {{ form_label(form) }}         {{ form_errors(form) }}         {{ form_widget(form, { 'attr': {'class': 'test'} }) }}       </div>     {% endspaceless %}     {% endblock %} 

and in app/config/config.yml:

   # twig configuration    twig:    //..      form:         resources:             - 'aliquamsummarybundle:form:fields.html.twig' 

the fields.html.twig rendered ok main twig error when removing 1 of hash in fields twig.


what's not working (i.e. class test doesn't show) when try make fields.html.twig take effect on article.html.twig:

   {% block aliquam_input %}    {% spaceless %}     <div class="well;">         <form method="post" {{ form_enctype(form) }}>             {{ form_widget(form) }}             <input type="submit" class="btn btn-primary" />         </form>     </div>    {% endspaceless %}    {% endblock %} 

as forms have same format, i'd prefer not set html attributes every single line. way class "test" taking effect fields.html.twig template?

___________________________ update david _____________ @david, unfortunately adding name form.name doesn’t change anything. css attribute still not transferred form in html. spot semicolon after well; late night typo, not related problem.

here have figured far. might have end having enter bootstrap css each individual row in form (horrible thought) or figure how entities options, comes same horrible thought doing every row. since doc offers enter template forms via app/config/config.yml there should far simpler way, don’t it.

the below direction far made css work little, i.e. class .test{background-color: black;} doing job:

    {# ..\addarticle.html.twig #}      <div class="well">         <form method="post" {{ form_enctype(form) }}>             {{ form_widget(form) }}             <input type="submit" class="btn btn-primary" />        </form>      </div> 

nb: there no {% block .. %} around div, makes sense put fields.html.twig included symphony standard widgets through app/config/config.yml. above goes fields.html.twig below.

   {# ..\fields.html.twig #}      {% block widget_attributes %}     {% spaceless %}           {{" class=\'test\'" }}     {% endspaceless %}     {% endblock widget_attributes %} 

so far fields textarea show black color, bit it’s kind of “hello world”. not sure if right way proceed have not found alike in , other forums , doc states @ form_div_layout.html.twig on git decide attribute change, not helpful (to me).

first change well; class well in add.article.html.twig.

in order put class on widget think can try

{{ form_widget(form.name, {'attr': {'class': 'test'}}) }} 

the difference code form.name parameter. if give form not apply passed options. see doc


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -