Skip to content

Instantly share code, notes, and snippets.

@k127
Created August 19, 2016 12:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save k127/c6d92618adeed90bd6e1efb1e261954b to your computer and use it in GitHub Desktop.
Save k127/c6d92618adeed90bd6e1efb1e261954b to your computer and use it in GitHub Desktop.
A simple minimal example for preprocessing PHP template data
<?php
// We just preprocess some data to use for the template.
// For what we want to show, it is not important what we're doing here exactly,
// rather than the fact that this cannot be done inside a Twig template,
// which is where this PHP HTML template should be convertet to.
if ($image = filter_input(INPUT_GET, 'image') &&
!filter_var($image, FILTER_VALIDATE_URL) === false) {
$image_src = $image;
}
?>
<?php if (isset($image_src)) : ?>
<div>
<a href="http://example.com/">
<img src="<?= addslashes($image_src) ?>"/>
</a>
</div>
<?php endif ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment