-
Notifications
You must be signed in to change notification settings - Fork 5k
Open
Labels
FeatureType: New FeatureType: New FeatureStalemigrationsymfony migration projectsymfony migration project
Description
Usecase: developers can override twig templates in order to modify a page display. For example if I prefer flat design over material design, I can re-style my BO with my design preference.
What happens if, while re-styling one template, I want to display an additional information using a variable that was not passed to Twig by the Controller ? As Symfony controllers are not overridable in PS 1.7, I might have to create a new Controller even though I just wanted to add 1 single extra variable. For example I just wanted to replace
return $this->render('@PrestaShop/Admin/Configure/AdvancedParameters/LogsPage/index.html.twig', [
'layoutHeaderToolbarBtn' => [],
'layoutTitle' => $this->trans('Logs', 'Admin.Navigation.Menu'),
'requireAddonsSearch' => true,
'grid' => $this->presentGrid($grid),
]);
by
return $this->render('@PrestaShop/Admin/Configure/AdvancedParameters/LogsPage/index.html.twig', [
'layoutHeaderToolbarBtn' => [],
'layoutTitle' => $this->trans('Logs', 'Admin.Navigation.Menu'),
'requireAddonsSearch' => true,
'grid' => $this->presentGrid($grid),
'extra_var' => $myExtraVariable
]);
Possible solutions:
- Declare a twig global variable, but this impacts all templates, not just the one I wanted (suggestion by @mickaelandrieu)
- Create a dedicated Twig Extension to be used in my template (suggestion by @mickaelandrieu)
- Add a listener to KernelEVENTS::CONTROLLER and KernelEvents::VIEW and perform a hook call there to enable variables injection
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
FeatureType: New FeatureType: New FeatureStalemigrationsymfony migration projectsymfony migration project