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?