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

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Support

TWIG template engine either "TWIG" or "PHP"

Started by Peter Ebbelink 8 years ago · 4 replies · 1124 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!

Suggested topics

Topic Participants Replies Views Activity
Support · by Thomas, 1 week ago
2 57 14 hours ago
Support · by Anna, 3 days ago
2 65 17 hours ago
Support · by Justin Young, 18 hours ago
1 33 18 hours ago
Support · by Duc , 1 week ago
2 68 5 days ago
Support · by Colin Hume, 1 week ago
2 60 6 days ago