twigHow to create a template in PHP Twig?
Creating a template in PHP Twig is a simple process.
{% extends "base.html" %}
{% block title %}My Page{% endblock %}
{% block body %}
<h1>My Page</h1>
<p>Welcome to my page!</p>
{% endblock %}
This example code will create a template that extends the base.html template, and adds a title and body block. The title block will contain the text "My Page", and the body block will contain an h1 tag with the text "My Page" and a paragraph tag with the text "Welcome to my page!".
{% extends "base.html" %}- This line tells Twig to extend the base.html template.{% block title %}My Page{% endblock %}- This line creates a title block with the text "My Page".{% block body %}- This line creates a body block.<h1>My Page</h1>- This line adds an h1 tag with the text "My Page" to the body block.<p>Welcome to my page!</p>- This line adds a paragraph tag with the text "Welcome to my page!" to the body block.{% endblock %}- This line ends the body block.
Helpful links
More of Twig
- How to write PHP code in Twig?
- How to use a PHP function in Twig?
- How to integrate Twig with Yii2?
- How to use Twig in PHP to get the current year?
- How to embed YouTube videos in Twig with PHP?
- How to use XOR in Twig with PHP?
- How to get a substring in PHP Twig?
- How to use the Twig library with PHP?
- How to use var_dump with PHP and Twig?
- How to use yield in Twig with PHP?
See more codes...