Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Twig not being processed in page content #1351

Closed
OvidiuS opened this issue Mar 14, 2017 · 6 comments
Closed

Twig not being processed in page content #1351

OvidiuS opened this issue Mar 14, 2017 · 6 comments
Labels

Comments

@OvidiuS
Copy link

OvidiuS commented Mar 14, 2017

Using Grav v1.1.17 - Admin v1.2.14
I turned on the setting for processing Twig on pages, in user/config/system.yaml:

  process:
      markdown: true
      twig: true
    twig_first: true
    never_cache_twig: true
  frontmatter:
    process_twig: true

but twig does not get processed if used in the content of a page. Something simple like {{ config.site.author.email }} gets outputted raw.

The only way to get twig to be processed in a page's content is to add this to the page's frontmatter:

process:
    twig: true

So the system setting is not being used by the pages, it needs to be re-set on a page-by-page basis.

@rhukster
Copy link
Member

Ok, i looked into this. I setup a fresh installation of the latest RC (should be the same as the stable version).

i changed the user/config/system.yaml like so:

pages:
  theme: antimatter
  markdown:
    extra: false
  process:
    markdown: true
    twig: true

then I setup my page with:

---
title: Home
---

# Grav is Running!
## You have installed **Grav** successfully

<h1>{{ page.title }}</h1>

The page title displayed just fine as expected. Turning off twig processing in system.yaml caused the twig code to be rendered as expected. Are you sure you set your configuration in user/config/system.yaml also did you ensure it was under the pages: block???

@OliverO2
Copy link
Contributor

I think I've found the cause and a fix:

Page::content() uses a combination of page configuration and system configuration to decide whether to call Page::processTwig().

Then Twig::processPage() get called which again evaluates the page configuration but forgets to look at the system configuration. I could successfully fix it in v1.1.17 by looking up line 233 in Twig.php:

$process_twig = isset($item->header()->process['twig']) ? $item->header()->process['twig'] : false;

and then adding an extra line immediately thereafter:

$process_twig = $process_twig || $this->grav['config']->get('system.pages.process.twig');

But maybe Twig::processPage() should get rid of $process_twig and just go ahead when Page::content() has already considered everything.

@rhukster
Copy link
Member

I still cannot replicate this, can someone provide me steps to replicate the issue??

@OliverO2
Copy link
Contributor

Could you​ try with a modular page? That's what we have here and that's what looking at the code seems to suggest.

@rhukster
Copy link
Member

Ok, found it, replicated it. Discovered the logic was a bit convoluted and in fact it was this convoluted logic that was leading to this issue. Should be sorted now. Please test the commit.

@OliverO2
Copy link
Contributor

Tested commit 10a15ef. Works as expected when toggling 'pages.process.twig' between 'true' and 'false'. Thanks and have a great week!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants