What's the purpose of Twig “include with only”?

后端 未结 1 1894
鱼传尺愫
鱼传尺愫 2021-02-07 18:31

What\'s really the purpose of include with only in Twig:

{# only the foo variable will be accessible #}
{% include \'child.html.twig\' with {\'foo\'         


        
相关标签:
1条回答
  • 2021-02-07 19:09

    When you include a template, it has access to all the variables available in the including template. If for some reason you don't want that, use the only keyword.

    I haven't been in a situation when I needed that, but there might be reasons other than performance. For example, you could use it to avoid naming collisions in some scenarios.

    0 讨论(0)
提交回复
热议问题