Skip to content

Instantly share code, notes, and snippets.

@Phunky
Created January 28, 2013 20:31
Show Gist options
  • Save Phunky/4658733 to your computer and use it in GitHub Desktop.
Save Phunky/4658733 to your computer and use it in GitHub Desktop.
Exploring ways to handle block component includes in just php (without a template system), not quite sure using the anonymous function is the best approach but removed need to have separate function to end the block although could do this with a class I just didn't like having to instantiate it on each block. Ideas?
<?
$content = 'content before';
function block($tpl){
ob_start();
return function() use ($tpl){
$content = ob_get_clean();
include('templates/' . $tpl . '.php');
};
}
?>
<style>
div {border: 1px solid red; margin: 5px; padding: 5px;}
</style>
<? $btn = block('button') ?>
This is my rifle. There are many like it, but this one is mine.
<? $btn = block('button') ?>
My rifle is my best friend. It is my life. I must master it as I must master my life.
<? $btn = block('button') ?>
My rifle, without me, is useless. Without my rifle, I am useless. I must fire my rifle true. I must shoot straighter than my enemy who is trying to kill me. I must shoot him before he shoots me. I will...
<? $btn() ?>
<? $btn() ?>
<? $btn() ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment