###This plugin is deprecated in favor of ekandreas/bladerunner
WordPress Blade
Brings Laravel's great template engine, Blade, to WordPress. Just install and start using blade in your theme.
Blade is the template engine for Laravel, a very popular php framework, developed by Taylor Otwell. This plugin brings the same template engine to WordPress. Using a template engine will result in much cleaner template files and quicker development. Normal php can still be used in the template files. The plugin also adds a WordPress specific snippet to blade. Check out the examples for more info.
WordPress Repository: Blade
Blade Tutorial on YouTube: Video Tutorial
Echo/Print
// Normal
echo $foo; ?>
// Blade
{{ $foo }}
Post Data
// Normal
the_title(); ?>
// Blade
{{ the_title() }}
If Statements
Normal
if( has_post_thumbnail() ) : ?>
the_post_thumbnail() ?>
else: ?>
<img src=" bloginfo( 'stylesheet_directory' ) ?>/images/thumbnail-default.jpg" />
endif; ?>
Blade
@endif ">@if( has_post_thumbnail() ) {{ the_post_thumbnail() }} @else "{{ bloginfo( 'stylesheet_directory' ) }}/images/thumbnail-default.jpg" /> @endif
WordPress Loop
Normal
-
$query = new WP_Query( array( 'post_type' => 'post' ) ); ?>
if ( $query->have_posts() ) : ?>
while ( $query->have_posts() ) : $query->the_post(); ?>
<li><a href=" the_permalink() ?>"> the_title() ?> a>li> endwhile; ?> else : ?> <li> _e( 'Sorry, no posts matched your criteria.' ) ?>li> endif; wp_reset_postdata(); ?> ul>
Blade
-
@wpquery( array( 'post_type' => 'post' ) )
- "{{ the_permalink() }}">{{ the_title() }} @wpempty
- {{ __( 'Sorry, no posts matched your criteria.' ) }} @wpend
Advanced Custom Fields
Normal
-
if( get_field( 'images' ) ): ?>
while( has_sub_field( 'images' ) ): ?>
<li><img src=" the_sub_field( 'image' ) ?>" />li>
endwhile; ?> endif; ?> ul>
Blade
-
@acfrepeater('images')
- {{ get_sub_field( 'image' ) }} @acfend
Including Files
Files included with functions, e.g. the_header()
, will not be compiled by Blade, however the php code in the file is still executed. To include a file with blade use:
@include( 'header' )
Note that you should not type “.php”.
Layouts
master.php
class="content"> @yield( 'content' )
page.php
@layout( 'master' )
@section( 'content' )
Lorem ipsum
@endsection
Documentation
Check out the complete Blade Documentation for more examples.
Contributing
Pull requests are highly appreciated. Feel free to report a bug, typo, enhancement or a feature you want to add to the plugin.