-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Added a new section to the page templating/global_vars using a EVListener #6794
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
5d0cb59
Added the new section and a DC notice
1688ff0
syntax error on ::note
e16733d
links fixed
f9c2827
again syntax problems in the links, im getting there
38733bc
And another attempt at fixing the links..
2140fd2
syntax errors..
0962824
syntax hopefully fixed, and suggested changes by @snoek09 processed
6181e29
.html in a :doc: link
9c8a533
removed both the suggested and twig section about globals
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -133,3 +133,28 @@ If the global variable you want to set is more complicated - say an object - | |
then you won't be able to use the above method. Instead, you'll need to create | ||
a :ref:`Twig Extension <reference-dic-tags-twig-extension>` and return the | ||
global variable as one of the entries in the ``getGlobals`` method. | ||
|
||
.. note:: | ||
|
||
``getGlobals`` is deprecated as of Twig v1.23 and removed in v2.0. | ||
|
||
Using an Event Listener Together with the @Template Annotation | ||
-------------------------------------------------------------- | ||
|
||
If you're using the `@Template`_ annotation from `SensioFrameworkExtraBundle`_ you can hook | ||
into ``kernel.view`` right before the template listener kicks in, take a look at the | ||
dedicated page about :doc:`Event Listeners </event_dispatcher.html>`_. | ||
|
||
Here is an example of changing the parameters when you have your listener set up: | ||
|
||
.. code-block:: php | ||
|
||
public function onKernelView(GetResponseForControllerResultEvent $event) | ||
{ | ||
$params = $event->getControllerResult(); | ||
$params['sadface'] = 'You need me everywhere!'; | ||
$event->setControllerResult($params); | ||
} | ||
|
||
.. _`@Template`: https://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/view | ||
.. _`SensioFrameworkExtraBundle`: http://symfony.com/doc/master/bundles/SensioFrameworkExtraBundle | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should point to |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The syntax error is caused by the underscore at the end of the :doc: link.
Something like this is fine: