Skip to content

Instantly share code, notes, and snippets.

@Triztan
Forked from AlexR1712/bladeCompile.php
Last active September 16, 2019 23:49
Show Gist options
  • Save Triztan/aab6b8a4952f4811835c73737616e503 to your computer and use it in GitHub Desktop.
Save Triztan/aab6b8a4952f4811835c73737616e503 to your computer and use it in GitHub Desktop.
Compile a string like Blade Template in Laravel
<?php
// Only you need to add in your controller.
public function bladeCompile($value, array $args = array())
{
$generated = \Blade::compileString($value);
ob_start() and extract($args, EXTR_SKIP);
// We'll include the view contents for parsing within a catcher
// so we can avoid any WSOD errors. If an exception occurs we
// will throw it out to the exception handler.
try
{
eval('?>'.$generated);
}
// If we caught an exception, we'll silently flush the output
// buffer so that no partially rendered views get thrown out
// to the client and confuse the user with junk.
catch (\Exception $e)
{
ob_get_clean(); throw $e;
}
$content = ob_get_clean();
return $content;
}
//https://laracasts.com/discuss/channels/general-discussion/render-template-from-blade-template-in-database
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment