@@ -32,10 +32,10 @@ For more information, see :doc:`/reference/configuration/tags`.
3232Setting and Invalidating Tags
3333-----------------------------
3434
35- You can tag responses in three ways: with the cache manager, configuration and
36- annotations.
35+ You can tag responses in different ways: with the tag handler from PHP or with
36+ a twig function, from configuration or using annotations on controller actions .
3737
38- Tagging from code
38+ Tagging from Code
3939~~~~~~~~~~~~~~~~~
4040
4141Inject the ``TagHandler `` (service ``fos_http_cache.handler.tag_handler ``) and
@@ -76,8 +76,31 @@ To invalidate tags, call ``TagHandler::invalidateTags($tags)``::
7676
7777See the :ref: `Tag Handler reference <tag_handler_addtags >` for full details.
7878
79- Configuration
80- ~~~~~~~~~~~~~
79+ Tagging from Twig Templates
80+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
81+
82+ In situations where a page is assembled in the templating layer, it can be more
83+ convenient to add tags from inside the template. This works the same way as
84+ with the tag handler and can also be mixed with the other methods:
85+
86+ .. code-block :: jinja
87+
88+ {# template.html.twig #}
89+ {{ fos_httpcache_tag('mytag') }}
90+ {{ fos_httpcache_tag(['tag-one', 'tag-two']) }}
91+
92+ .. hint ::
93+
94+ This twig function never outputs anything into the template but is only
95+ called for the side effect of adding the tag to the response header.
96+
97+ .. note ::
98+
99+ Tag invalidation from twig would be a strange architecture and is therefore
100+ not supported.
101+
102+ Tagging with Configuration Rules
103+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
81104
82105Alternatively, you can :doc: `configure rules </reference/configuration/tags >`
83106for setting and invalidating tags:
@@ -97,8 +120,8 @@ Now if a :term:`safe` request matches the criteria under ``match``, the response
97120will be tagged with ``news ``. When an unsafe request matches, the tag ``news ``
98121will be invalidated.
99122
100- Annotations
101- ~~~~~~~~~~~
123+ Tagging with Controller Annotations
124+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
102125
103126Add the ``@Tag `` annotations to your controllers to set and invalidate tags::
104127
0 commit comments