How to get processed content from a modular page in a custom plugin

Hello,
I would like to append modular page content in PHP by:

    public function onPagesInitialized(Event $e)
    {
        if ($this->isAdmin()) {

            $grav = Grav::instance();
            $grav['admin']->enablePages();
            $getItem = $grav['pages']->find('/global-variables-and-templates/service/template/_twigtemplate');
            $test = $grav['twig']->processPage($getItem);
            dump($getItem->content());
            exit();
        }
    }

but the result is not processed by twig… my content:

{% set page = page.find('/global-variables-and-templates/service/data/_austria') %} 
{% set data = page.header.content.show %} 
{% set path = uri.path %} 
{% set items = '' %} 
{% set heading = 'NONE!!!' %}
{% set description = '' %} 
{% set typeService = '' %} 
{% for value in data if path in attribute(value,'service-pages')%} 
    {% set items = value.items %} 
    {% set heading = attribute(value,'service-heading') %}
    {% set description = attribute(value,'service-description') %} 
    {% set typeService = attribute(value,'service-type') %} 
{% endfor%} 
{% set col = 'col col-12 col-sm-6 col-lg-4 col-xl-3' %} 
{% if typeService == 'short-v' %} 
    {% set col = 'col col-12 col-md-6 col-lg-3' %} 
{% endif %}
<section class="we-offer-area text-left">
    <div class="container">
        <div class="row">
            <div class="col col-12 text-center">
                <h2 class="h2 py-5 fw-bolder">{{heading |raw}}</h2>
                {% if description %}
                <p class="fs-4 pb-5">{{description|raw}}</p>
                {% endif %}
            </div>
        </div>
        <div class="row our-offer-items less-carousel justify-content-center">
            {% for item in items %} {% set dataService = attribute(page.header.services,item) %} {% if loop.index == 4 and typeService != 'short-v' %}
            <div class="w-100 d-none d-lg-block"><br /></div>
            {% endif %}
            <div class="{{col}} {{typeService}}" data-id="{{item}}">
                <a href="{{dataService.link}}" title="{{dataService.title}}">
                    <div class="item rounded-carousel h-100 bg-orange-light px-4">
                        {% set iconHover = attribute(dataService,'icon-hover')|raw %} {% if dataService.icon %}
                        <div class="fas">
                            {% if typeService != 'short-v' %} <img class="bg-icon" src="{{dataService.icon|raw}}" alt="{{dataService.alt|raw}}" title="{{dataService.alt|raw}}" />{% if iconHover %}
                            <img class="bg-icon hover-icon" src="{{iconHover}}" alt="{{dataService.alt|raw}}" title="{{dataService.alt|raw}}" />{% endif %} {% endif %}
                        </div>
                        {% endif %}
                        <h3 class="h4 fw-bold pb-5 pt-3">{{dataService.heading|raw}}</h3>
                        <p class="fs-5">{{dataService.description|raw}}</p>
                        <div class="text-more px-4 mt-2 fs-5 fw-ligh">{{dataService.button |raw}}</div>
                    </div>
                </a>
            </div>
            {% endfor %}
        </div>
    </div>
</section>

if I call the onPagesInitialized function on the web then the result is fine (processed by twig) but if I call this function in administration then twig is not processed, how can I save the processed content of a modular page in administration (in my custom plugin) in a variable?

@danielkoptak, Please help the community helping you by providing clear and succinct questions containing relevant information.

  • What are you trying to achieve?
  • What should the result look like?
  • What are you getting instead?
  • When showing code:
    • From which file is the code snippet a relevant part.
    • What is the purpose of the code.
    • Don’t show all code, but only relevant code.
    • Trim down all code to a bare, but still reproducible, minimum.
    • If needed, add some helpful comments to clarify.

In other words: Show the reader you’ve spent time to help the reader spend less time trying to understand the issue.

Your return on investment: This will increase the likelihood the question will be answered.

Some feedback:

I would like to append modular page content in PHP by:

  • To what would you like to append the content of the modular page to? Your PHP code is not adding the content to anything.
  • What should the end result be like? And what are you getting?

‘/global-variables-and-templates/service/template/_twigtemplate’

  • Is above the path to a template, or a module, or …?
  • Please use sensible names.

but the result is not processed by twig

  • What do you mean by “is not processed”? Is only raw markdown shown? Or is nothing shown? Or do you get an error, or …

my content

  • Content of what? It this Twig code embedded in you page or is the the template of the modular page or module?
  • Is all this Twig code needed for the reader to understand the issue/problem?
    To prove Twig “is not processed” the following Twig code in the template will be enough:
    <p>Twig is being processed<p>