Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Question

Post Timeline

deleted 12 characters in body
Source Link
Peyman Mohamadpour
  • 18.1k
  • 24
  • 94
  • 102

What is the difference between use and include in Twig? #Documentation:

include

The include statement includes a template and returns the rendered content of that template into the current one:

{% include 'header.html' %}
Body here...
{% include 'footer.html' %}

use - The use statement tells Twig to import the blocks defined in blocks.html into the current template (it's like macros, but for blocks):

blocks.html

{% block sidebar %}{% endblock %}

main.html

{% extends "base.html" %}
{% use "blocks.html" %}
{% block title %}{% endblock %}
{% block content %}{% endblock %}

#Possible answer:

I think this should explain the difference:

include is to get all the code from an external file and import it into your actual file at the right location of the call.

use is completely different as it parses the linked file to find a particular section of code and then overwrites the blocks with the same name, in your current file, with the one found in this external file.

include is like "go find this file and render it with my page here".

use is "parse this other file to find block definitions to use instead of my owns defined here".

If use command finds nothing matching the task, nothing is displayed at all from this file.


#Question is the explanation correct? are there any other explanations to this difference?

thanks

What is the difference between use and include in Twig? #Documentation:

include

The include statement includes a template and returns the rendered content of that template into the current one:

{% include 'header.html' %}
Body here...
{% include 'footer.html' %}

use - The use statement tells Twig to import the blocks defined in blocks.html into the current template (it's like macros, but for blocks):

blocks.html

{% block sidebar %}{% endblock %}

main.html

{% extends "base.html" %}
{% use "blocks.html" %}
{% block title %}{% endblock %}
{% block content %}{% endblock %}

#Possible answer:

I think this should explain the difference:

include is to get all the code from an external file and import it into your actual file at the right location of the call.

use is completely different as it parses the linked file to find a particular section of code and then overwrites the blocks with the same name, in your current file, with the one found in this external file.

include is like "go find this file and render it with my page here".

use is "parse this other file to find block definitions to use instead of my owns defined here".

If use command finds nothing matching the task, nothing is displayed at all from this file.


#Question is the explanation correct? are there any other explanations to this difference?

thanks

What is the difference between use and include in Twig? #Documentation:

include

The include statement includes a template and returns the rendered content of that template into the current one:

{% include 'header.html' %}
Body here...
{% include 'footer.html' %}

use - The use statement tells Twig to import the blocks defined in blocks.html into the current template (it's like macros, but for blocks):

blocks.html

{% block sidebar %}{% endblock %}

main.html

{% extends "base.html" %}
{% use "blocks.html" %}
{% block title %}{% endblock %}
{% block content %}{% endblock %}

#Possible answer:

I think this should explain the difference:

include is to get all the code from an external file and import it into your actual file at the right location of the call.

use is completely different as it parses the linked file to find a particular section of code and then overwrites the blocks with the same name, in your current file, with the one found in this external file.

include is like "go find this file and render it with my page here".

use is "parse this other file to find block definitions to use instead of my owns defined here".

If use command finds nothing matching the task, nothing is displayed at all from this file.


#Question is the explanation correct? are there any other explanations to this difference?

edited title
Link
Peyman Mohamadpour
  • 18.1k
  • 24
  • 94
  • 102

Difference between use & includeInclude, Extends, Use, Macro, Embed in Twig

Source Link
Peyman Mohamadpour
  • 18.1k
  • 24
  • 94
  • 102

Difference between use & include in Twig

What is the difference between use and include in Twig? #Documentation:

include

The include statement includes a template and returns the rendered content of that template into the current one:

{% include 'header.html' %}
Body here...
{% include 'footer.html' %}

use - The use statement tells Twig to import the blocks defined in blocks.html into the current template (it's like macros, but for blocks):

blocks.html

{% block sidebar %}{% endblock %}

main.html

{% extends "base.html" %}
{% use "blocks.html" %}
{% block title %}{% endblock %}
{% block content %}{% endblock %}

#Possible answer:

I think this should explain the difference:

include is to get all the code from an external file and import it into your actual file at the right location of the call.

use is completely different as it parses the linked file to find a particular section of code and then overwrites the blocks with the same name, in your current file, with the one found in this external file.

include is like "go find this file and render it with my page here".

use is "parse this other file to find block definitions to use instead of my owns defined here".

If use command finds nothing matching the task, nothing is displayed at all from this file.


#Question is the explanation correct? are there any other explanations to this difference?

thanks

lang-php

AltStyle によって変換されたページ (->オリジナル) /