Use PHP Variables in Markdown
uvulpos opened this issue · 3 comments
uvulpos commented
Hey,
I use Parsedown for my Imprint and Privacy Policy so my lawyer can read it and I have to specify some sources from my database. These documents are in one file. How can I insert them? Maybe something like this could be a nice to have feature. At least I found no documentation 🤷🏻♂️
<?php
$current_date = date("Y-m-d");
$Parsedown = new Parsedown();
$Parsedown->setVariables(array(
'current_date' => $current_date
));
echo $Parsedown->text("Today is: {current_date}");
?>
<!-- output -->
Today is: 2020-12-15
taufik-nurrohman commented
Using plain str_replace()
to replace variable after parsed:
$text = $Parsedown->text('Today is: {current_date}');
$vars = [
'current_date' => date('Y-m-d'),
'client' => 'Tom',
// ...
];
foreach ($vars as $var => $value) {
$text = str_replace('{' . $var . '}', $value, $text);
}
echo $text;
uvulpos commented
This would make sense yes, right now I'm doing it this way but I wish there was something like this as a feature in Markdown
acicali commented
My opinion is that this is not what Markdown was created for. You should use a templating engine for this... something like Mustache.