Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Symfony2 Essentials

You're reading from   Symfony2 Essentials

Arrow left icon
Product type Paperback
Published in Sep 2015
Publisher
ISBN-13 9781784398767
Length 158 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Toc

Theming form elements

So far our form does not look too pretty. It's just a basic form without any fancy styles. Symfony2 provides a very flexible way to customize form rendering using Twig templates called form theme.

Form theme is just a regular Twig template but filled with blocks to render form rows, labels, inputs, errors, text areas, select boxes, checkboxes, and so on.

By default, Symfony2 uses a theme called form_div_layout.html.twig. The file with this form style is located in vendor/symfony/symfony/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig, and it is good to review this and see how it's organized. It is, of course, possible to change this easily.

Let's create our own theme based on the default theme. Create the app/Resources/views/Form/theme.html.twig file and fill it with the following content:

{% use 'form_div_layout.html.twig' %}

{%- block form -%}
    {{- form_start(form, { attr: { class: 'ui form small', novalidate...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image