A
A
andreyqin2014-01-20 14:40:13
Twig
andreyqin, 2014-01-20 14:40:13

Problem with block inheritance in twig

I decided to make the contents of the tag in the form of templates, since on each page some files are connected, some are not. I shoved all the possible content into a separate file with something like this:

{% block meta %}<meta http-equiv="Content-Type" content="text/html; charset=utf-8">{% endblock %}
{% block style %}<link rel="stylesheet" type="text/css" href="css/style.css">{% endblock %}
{% block jquery %}<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>{% endblock %}
{% block script %}<script src="js/script.js"></script>{% endblock %}

In the template I need, in the tag <head>, I do the inserts I need like this: {% block meta %}{% endblock %}etc., but the blocks are not connected. I tried to add the path to the inherited file to the beginning of the file with blocks, for example {% extends "../index.html" %}, but to no avail.
The site structure is something like this:
/css
/js
/templates
   /nodes
      -head.html
      ...
   -index.html
   -contacts.html
   -about.html
/images
/includes
-index.php
-contacts.php
-about.php

PHP files chain their respective templates. Head.html contains the same blocks for the head tag, which should be connected to the html files in the folder above. Tell me why blocks are not inherited by templates?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilyas Masirov, 2014-01-20
@andreyqin

Inheritance occurs with parents(), i.e. inherit the template using extends and then inherit the parent methods in the body of the block:{% block meta %} parents() {% endblock %}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question