WmZilla - Webmaster and Marketplace

The Next Generation Webmaster and Trade Forum

Using Twig Blocks in Symfony

rie

New member

0

0%

Status

Offline

Posts

16

Likes

0

Rep

0

Bits

90

3

Months of Service

0%
Symfony framework comes by default with the Twig template system.

Assuming we need to extend one or more templates to differentiate areas of our application:

Insert CODE, HTML, or PHP:
```
{% extends 'base.html.twig' %}
```

Assuming we want to add a title to a default view:

Insert CODE, HTML, or PHP:
```
{% block title %}MyCRM - About{% endblock %}
```

Assuming we want to add SEO-friendly meta tags:

Insert CODE, HTML, or PHP:
```
{% block meta %}
<meta name="description" content="your content description">
<meta name="keywords" content="keyword 1, Keyword 2, etc"/>
{% endblock %}
```

With Twig, by opening and closing blocks, we can add extra logic to our applications. A simple example is adding a large number of CSS and JS files to the main template, which loads for every view, making applications slow and unattractive to SEO. By using blocks, we can divide these for specific views where we need to use a certain resource.
 

249

6,622

6,642

Top