Skip to content
Grav 2.0 is officially stable. Read the announcement →
Support

TWIG template engine either "TWIG" or "PHP"

Started by Peter Ebbelink 8 years ago · 4 replies · 1484 views
8 years ago

Hi,
on the website http://symfony.com/doc/current/templating/PHP.html Symphony mentions that TWIG can use two engines for processing templates: TWIG and PHP.
TWIG determines the difference by the extension:
myFile.html.twig is processed by the TWIG engine,
myFile.html.php is processed by the PHP engine.
Can I convince GRAV to obey this convention?
Currently I seem to only be able to use the TWIG engine.
I need to create a template that pulls data from a MySQL database and this seems a more appealing way than writing a TWIG extension.
Anyone has insight on this topic?

Thanx in advance!

Regarz, Peter

8 years ago

I'm afraid I can't answer your specific question, but why not write a plugin that pulls the data from SQL and then injects that data into the Twig variable space? Your standard Twig template then displays that data. That might be the simplest approach.

👍 1
8 years ago

Thanx for replying PerlKonig.
Jep, I might.
But

  1. I'm not that experienced in this field and (the most important)
  2. TWIG is said to have a built in mechanisme to switch engines (between TWIG and PHP, depending on the extension (".HTML.TWIG" and ".HTML.PHP")

So, why reinvent the wheel? ..... I just can't find the wheel ....

Cheers, Peter

8 years ago

I hope someone can answer your question. If you decide to go the other route, here are two plugins that do what I mentioned:

  • Import loads files given in the frontmatter and makes the data avaialable to Twig.
  • IPLocate runs the visitor's IP address through one or more services and injects the results into Twig.

Good luck!

8 years ago

Cool Perlkonig!
Thanx for your assistance!

cheers, Peter

Suggested topics

Topic Participants Replies Views Activity
Support · by Anna, 16 hours ago
1 46 9 hours ago
Support · by gtx, 1 week ago
4 227 2 days ago
Support · by Paul Hodges, 2 weeks ago
13 277 5 days ago
Support · by Anna, 3 weeks ago
9 334 1 week ago
Support · by TomW, 2 weeks ago
4 188 2 weeks ago