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.

Plugins

Getting twig processed content

Started by Richard Hainsworth 8 years ago · 1 replies · 720 views
8 years ago

How to get twig processed content inside a shortcode?

I want to write

TWIG
[sql-table]
select * from table where id={{ userinfo.id }}
[/sql-table]

I am using the sqlite and persistent-data plugins (which I wrote and are on the downloads page). sqlite gives the shortcode and persistent-data makes form fields into a twig variable.

Inside the [sql-table] shortcode, I have

PHP
$stanza = $sc->getContent();

However, dumping $stanza gives me select * from table where id={{ userinfo.id }}.

{{ userinfo.id }} should be 3 after being processed by twig.

Interestingly, the error message generated by the SQLite3 sql engine refers to a bad '{', but when the stanza is dumped via the error template (the expected action in sqlite for an error), I see a where id=3.

So what I want to know is how to force a twig processing on content inside a shortcode.

8 years ago

[frustration]!! [Solved].

The answer is

PHP
$stanza = $this->grav['twig']->processString($sc->getContent());

Suggested topics

Topic Participants Replies Views Activity
Plugins · by Rene, 1 week ago
2 46 1 week ago
Plugins · by Xavier, 4 weeks ago
2 55 4 weeks ago
Plugins · by Luka Prinčič, 7 years ago
3 1181 1 month ago
Plugins · by Sebastian van de Meer, 1 month ago
1 49 1 month ago
Plugins · by PIERROT Alain, 2 months ago
3 73 2 months ago