Last active
July 16, 2018 13:35
-
-
Save mleko/7844a73c257eeb8cd655d00cc74e0e2e to your computer and use it in GitHub Desktop.
Very simple template "engine"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function render($template, $vars) { | |
return \preg_replace_callback("!{{\s*(?P<key>[a-zA-Z0-9_-]+?)\s*}}!", function($match) use($vars){ | |
return isset($vars[$match["key"]]) ? $vars[$match["key"]] : $match[0]; | |
}, $template); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment