Parse Markdown in Laravel 4 Blade Templates
Problem: you want to use Markdown for some content in the database, and to display it in your blade template.
Solution: composer require 'michelf/php-markdown'
and then add this to your app/start/global.php:
Blade::extend(function($view, $compiler) {
$pattern = $compiler->createMatcher('markdown');
$replace = '<?php echo \Michelf\Markdown::defaultTransform$2; ?>';
return preg_replace($pattern, $replace, $view);
});
// usage, in a blade template:
// @markdown( $some->property )
// or
// @markdown('some string *with style*')
Written by Pete Otaqui
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Markdown
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#