Shortcodes break Twig processing in pages

Using a stock install with Antimatter.

The page in question:

\```
title: Test
process:
    markdown: true
    twig: true
\```

This is a test page.

{{ test }}

Here is another line.

[section name="test"]
This line is in a shortcode.
[/section]

In antimatter.php:

<?php
namespace Grav\Theme;

use Grav\Common\Theme;

class Antimatter extends Theme
{
  public static function getSubscribedEvents()
  {
    return [
      'onTwigSiteVariables' => ['onTwigSiteVariables', 0]
    ];
  }

  public function onTwigSiteVariables()
  {
    $this->grav['twig']->twig_vars['test'] = 'Hello World!';
  }
}

When I add the shortcode, neither the shortcode nor the Twig variable gets processed.

It seems like either Twig or shortcodes can be processed, but not both.

Am I missing something?

Here’s the template that the page is using:

default.html.twig

{% extends 'partials/base.html.twig' %}

{% block content %}
	{{ page.content }}

	<h2>Extra Content</h2>

	<p>
		{{ shortcode.section.test }}
	</p>
{% endblock %}

They should not interfere. Will test real quick. stand by…

Ok easy fix! I just realized you have your Twig var being set by onTwigSiteVariables() which runs after the page is processed. What you need is onTwigPageVariables() to make it available for the page.

The way you had it, you could of put the {{ test }} in the template’s TWIG file, and it would of showed fine, but to be available in both pages and the site templates, you need to set that that even to onTwigPageVariables()… Here’s my test:

    public static function getSubscribedEvents()
    {
        return [
            'onTwigPageVariables' => ['onTwigPageVariables', 0],
            'onTwigSiteVariables' => ['onTwigSiteVariables', 0]
        ];
    }

    public function onTwigPageVariables()
    {
        $this->grav['twig']->twig_vars['test'] = 'Hello World! in Page';
    }

    public function onTwigSiteVariables()
    {
        $this->grav['twig']->twig_vars['test'] = 'Hello World! in Site';
    } 
---

Fantastic!
The Grav team is astronomically awesome!