Templating and Forms in Symfony: Using Twig for Creating and Submitting Forms, Lecture notes of Web Design and Development

An overview of templating and forms in Symfony, focusing on the use of Twig for creating and submitting forms. Topics covered include template locations, Twig language features, form creation methods, and various form input types. Twig extensions, macros, and blocks are also discussed.

Typology: Lecture notes

2019/2020

Uploaded on 05/11/2022

huy-cung
huy-cung 🇻🇳

5

(1)

32 documents

1 / 28

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Templating, Forms
Returning Views, using Twig, submitting forms
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c

Partial preview of the text

Download Templating and Forms in Symfony: Using Twig for Creating and Submitting Forms and more Lecture notes Web Design and Development in PDF only on Docsity!

Templating, Forms

Returning Views, using Twig, submitting forms

1. Templating

2. Forms

Table of Contents 2

• In Symfony you can use two type of templates

– php - standard html + php code in our templates

– twig - flexible template language

Templating

4

  • Templates Location
    • per application - templates can be accessed from any bundle
    • per bundle - templates can be accessed from any bundle
  • using the namespace notation Templating
  • Twig and Controllers
    • pass parameters to template
    • $this->render() - render template and create Response object
    • $this->renderView() - render Templating
  • Twig Templating

§ {{ … }} - print variable or text

§ {# … #} - twig comment

§ {% ... %} - used for logic blocks

  • What can we do with Twig?
    • app.user - get current user
    • app.request - get current request
    • app.session - get session
    • app.environment - get application environment
    • app.debug - check debug status of the application
    • access global twig variable - can create global twig variables and access them in your templates Templating

FORMS

Forms and Templates

  • Form flow Forms
  • Two ways to create forms in Symfony
    • in your controller action using the form builder Forms
  • A form should know what input field to render
    • TextType - input type="text"
    • SubmitType - input type="submit"
    • ChoiceType - generates select, checkboxes or radio buttons
    • HiddenType - input type="hidden"
    • RepeatedType - used to render input fields for passwords and confirmation Forms
  • To display form in template it must be passed as view

parameter

Forms

Folder Structure

Note.php