Created
June 2, 2020 12:22
-
-
Save kobus1998/4f2d3ee4d7354bfca82589bded74b09b to your computer and use it in GitHub Desktop.
super simple php/html template
This file contains 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 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