An enzyme for transcluding a web page

2018-06-14: This post was very different when I first published it, many years ago. Time goes by, and IFRAME is no longer that good an option when websites can specify new headers like X-Frame-Options. Meanwhile, I also had to deactivate my Enzymes plugin and only keep my newer Nzymes plugin active. Confronted with the alternative to leave this here as a useless contribution to mankind, I opted for changing the examples while keeping their original spirit instead.

Enzymes Nzymes can be complex PHP scripts, but basic enzymes are also very useful. These allow to transclude some web content into a post. Enzymes Nzymes makes it easy to do it over and over, without having to remember: “how did I do it?”

This is got by the statement {[.show-image()]}:

This is got by the statement {[.show-quote()]}:

We didn’t lose the game; we just ran out of time. (by Vince Lombardi)

show-image:

return "<img src='https://picsum.photos/200/300/?random' />";

show-quote:

$response = file_get_contents('https://random-quote-generator.herokuapp.com/api/quotes/random');
$decoded = json_decode($response, TRUE);
$quote = htmlspecialchars($decoded['quote']);
$author = htmlspecialchars($decoded['author']);
return "<span>$quote (by $author)</span>";

Easy, isn’t it?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.