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

PHP code in .md files

Started by Muut Archive 11 years ago · 6 replies · 851 views
11 years ago

Hello (it's me again),

how do I use (implement?) php scypts to my pages? I'd like to add simple script (to blog item) that reads directory and displays it's content as links. Do I need a extension for it? Or I can just use <?php ?> in .md file?

11 years ago

You can't put PHP in markdown files, that's simply not allowed. You can put Twig in markdown however to perform 'logic'.

If you REALLY wanted PHP in Twig, you could install a Twig extension that provided that capability but its really frowned upon. and not something I would advise at all.

11 years ago

What I rly want, is directory content as links, not necessarily via .PHP :)

11 years ago

I assume I need to add them manually in Markdown.

11 years ago

You might be better off creating a Grav plugin that loads the directory and stores the results as a variable in the Twig environment. Then you can simply loop over the results in that variable in the Twig template, or even the markdown page if you put the Twig in there.

10 years ago

You can put Twig in markdown however to perform ‘logic’.
How can I do that? I have some data in twig_vars and I'd like to present them in .md file

10 years ago

ok I have solution, just put this at the beginning of .md file:

YAML
title: Some Title
...
process:
    twig: true        

and then the usual {{ whatever }}

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1362 9 years ago
Archive · by Muut Archive, 9 years ago
2 939 9 years ago
Archive · by Muut Archive, 9 years ago
2 4069 9 years ago
Archive · by Muut Archive, 9 years ago
1 2959 9 years ago
Archive · by Muut Archive, 9 years ago
3 1124 9 years ago