How do I pass a variable to a twig template from a preprocess function of a views style plugin in a custom module?
In alpha.module
, I have tried:
function alpha_preprocess_views_view(&$variables) {
$variables["beta"] = "1";
}
and
function alpha_preprocess_page(&$variables) {
$variables["beta"] = "1";
}
The template file is alpha-gamma.html.twig
and the plugin is Gamma.php
:
/**
* Style plugin.
*
* @ViewsStyle(
* id = "gamma",
* title = @Translation("Gamma"),
* help = @Translation("Displays gamma."),
* theme = "alpha_gamma",
* display_types = {"normal"}
* )
*/
class Gamma extends StylePluginBase {
...
}
The template file is invoked and renders its output on the view's row results. However, {{ beta }}
yields no result in the same file. I know I'm missing something important, but none of the examples I've found are specific to this type of row style template.
Guidance would be appreciated!