How can I Effectively Display Blade code stored in a DB instead of being displayed as a line of code?
here is the image
Inspecting the html I see " {{HTML::ul(array('a', 'b', 'c'))}} " If I can get rid of the quotes the blade content will be displayed
You can compile blade syntax string, stored in a DB row or a variable by extending Blade Compiler. Solution code taken from here, I have not tested the code myself.
<?php namespace Laravel\Enhanced;
use Illuminate\View\Compilers\BladeCompiler as LaraveBladeCompiler;
class BladeCompiler extends LaraveBladeCompiler {
/**
* Compile blade template with passing arguments.
*
* @param [type] $value [description]
* @param array $args [description]
* @return [type] [description]
*/
public function compileWiths($value, array $args = array())
{
$generated = parent::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;
}
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments