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 embed YouTube videos in Twig with PHP?
- How to use a Twig variable in PHP?
- Where can I convert PHP to Twig online?
- How to get a substring in PHP Twig?
- How to format a number using PHP and Twig?
- How to use Twig in PHP to get the current year?
- How to check if a string contains a substring in PHP Twig?
- How to use yield in Twig with PHP?
- How to parse XLSX in Twig with PHP?
- How to use Slim/Twig-View in PHP?
See more codes...