I am trying to include another template file with pre-process's theme hook variables in a template file but it failed. I checked theme debug and it does not include example's pre-process theme hook. Can you give me guidance?
I added {% include 'example--p1.html.twig' %}
in the page--front.html.twig file. The example--p1.html.twig file has one variable, {{ test }}
. Also, I created a pre-process function that adds variables to a page template. The code is the following.
function mytheme_preprocess_example__p1(array &$variables, $hook) {
$variables['test'] = 'please help';
$variables['test_var'] = 'this is my second variable';
}
It doesn't appear in the example--p1.html.twig template.
Someone suggested using the following code in the page--front.html.twig file.
{% include 'example--p1.html.twig' with {'test' : 'this is my message'} %}
I then added the following code in the following files.
mytheme.theme
function mytheme_preprocess_example__p1(array &$variables, $hook) {
$variables['content']['text'] = 'second';
}
page--front.html.twig
{% include 'example--p1.html.twig' with {'test' : 'content.text'} %}
It works as it shows the text message value in example--p1.html.twig and page--front.html.twig.
How can I pass pre-process function's text messages' variables to page example--p1.html.twig and then I can display all the variables if I include example--p1.html.twig to page--front.html.twig?