Skip to content

Instantly share code, notes, and snippets.

@kobus1998
Created June 2, 2020 12:22
Show Gist options
  • Save kobus1998/4f2d3ee4d7354bfca82589bded74b09b to your computer and use it in GitHub Desktop.
Save kobus1998/4f2d3ee4d7354bfca82589bded74b09b to your computer and use it in GitHub Desktop.
super simple php/html template
<?php
function html($name, $attr = [], $value)
{
$s = "<{$name} ";
if (!empty($attr)) {
foreach ($attr as $key => $val) {
$s .= "{$key}=\"{$val}\" ";
}
}
$s = trim($s);
$s .= ">";
$s .= is_callable($value) ? $value() : $value;
$s .= "</{$name}>";
return $s;
}
echo html("div", ['class' => 'wrapper'], function () {
return
html("p", null, "lorem ipsum")
. html("p", null, "lorem ipsum");
});
// <div class="wrapper"><p>lorem ipsum</p><p>lorem ipsum</p></div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment