Coder Social home page Coder Social logo

blade's Introduction

###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
<?php echo $foo; ?>

// Blade
{{ $foo }}

Post Data

// Normal
<?php the_title(); ?>

// Blade
{{ the_title() }}

If Statements

Normal

<?php if( has_post_thumbnail() ) : ?>
    <?php the_post_thumbnail() ?>
<?php else: ?>
    <img src="<?php bloginfo( 'stylesheet_directory' ) ?>/images/thumbnail-default.jpg" />
<?php endif; ?>

Blade

@if( has_post_thumbnail() )
    {{ the_post_thumbnail() }}
@else
    <img src="{{ bloginfo( 'stylesheet_directory' ) }}/images/thumbnail-default.jpg" />
@endif

WordPress Loop

Normal

<ul>
	<?php $query = new WP_Query( array( 'post_type' => 'post' ) ); ?>
	<?php if ( $query->have_posts() ) : ?>
	        <?php while ( $query->have_posts() ) : $query->the_post(); ?>
	        <li><a href="<?php the_permalink() ?>"> <?php the_title() ?> </a></li>
	        <?php endwhile; ?>
	<?php else : ?>
	        <li><?php _e( 'Sorry, no posts matched your criteria.' ) ?></li>
	<?php endif; wp_reset_postdata(); ?>
</ul>

Blade

<ul>
	@wpquery( array( 'post_type' => 'post' ) )
	        <li><a href="{{ the_permalink() }}">{{ the_title() }}</a></li>
	@wpempty
	        <li>{{ __( 'Sorry, no posts matched your criteria.' ) }}</li>
	@wpend
</ul>

Advanced Custom Fields

Normal

<ul>
    <?php if( get_field( 'images' ) ): ?>
        <?php while( has_sub_field( 'images' ) ): ?>
            <li><img src="<?php the_sub_field( 'image' ) ?>" /></li>
        <?php endwhile; ?>
    <?php endif; ?>
</ul>

Blade

<ul>
    @acfrepeater('images')
        <li>{{ get_sub_field( 'image' ) }}</li>
    @acfend
</ul>

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

<html>
    <div class="content">
        @yield( 'content' )
    </div>
</html>

page.php

@layout( 'master' )

@section( 'content' )
    <p>Lorem ipsum</p>
@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.

blade's People

Contributors

3runodesign avatar jaggy avatar kexhest avatar mikaelmattsson avatar mykebates avatar omriyariv avatar pablovallejo avatar perholmang avatar relu avatar vinkla avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

blade's Issues

Help to adapt Blade plugin

Hi @mikaelmattsson
I'm working in a repo combining Laravel with Wordpress. Your plugin is just what I want, but I would like to implement using the already View facade provided by the Laravel, but I tried without success. :-(
Using your plugin works fine, but you did bring the Blade to WP. On my case I already have access to Laravel stuff.
Could you help me? Any advice would be nice.

My repo: https://github.com/bruno-barros/w.eloquent

Version of Blade?

Hey I was just wondering what version of blade this plugin uses?! Looks like @layout() was replaced with @extends() in version 4, so i'm wondering which to use.

I assume 3, but it'd be nice to see which version somewhere in the readme and on the plugin description page on Wordpress.org.

Thanks, nice plugin!

Bound data / view variables

Hi,

I'm trying to include data with my templates. Both of these render nothing for {{ $title }}:

@include('partials/sighting-top', array('title' => 'My Title'))       // usual way
@include('partials/sighting-top')->with('title','My Title')            // should work to?

So I look at this:
blade.php#L332-L337

and wonder about ->with(get_defined_vars()).

Doesn't this just rewrite my $title to null, since no value is supplied?

view.php#L452-L463

Issue with Wordpress Template Names

The beginning of my template file is like this:
@layout('layouts.master')
{{-- Template Name: MySuperTemplate --}}

In the wp-admin page template dropdown menu the template will read as:
MySuperTemplate --}}

A way to bypass this would be to place the comment in the template file like this
{{-- Template Name: MySuperTemplate --
}}

But this is not optimal.
{{-- Template Name: MySuperTemplate --}} would be preferred.

Would this be possible to fix / implement in the plugin?

Latest Blade Version?

Is this plugin compatible with the latest version of Blade or are there any plans to update?

I've been looking to learn Laravel for more complex projects and it seems like this could be a step in the right direction.

Thanks,

Warning: file_put_contents

Hi,

Love the idea of this, but after installing the plugin, I just get a series of errors:

Warning: file_put_contents(/Users/XXX/Desktop/XXX/wp-content/plugins/blade/storage/views/b53abbc6886c9f3bc6e767c1fc5198d6): failed to open stream: Permission denied in /Users/XXX/Desktop/XXX/wp-content/plugins/blade/application/models/main-model.php on line 47

This is then repeated on:

Warning: include(/Users/XXX/Desktop/XXX/wp-content/plugins/blade/storage/views/b53abbc6886c9f3bc6e767c1fc5198d6): failed to open stream: No such file or directory in /Users/XXX/Desktop/XXX/wp-includes/template-loader.php on line 74

Tests?

Are there any tests on this plugin?
If not it is urgent that we do that because the plugin is so nice and useful. Stability needed!

Repo missing version

To get the composer install to work you need to set the tag on the repo, eg: v0.3.7

Blade not working

Hi,

FIrst of all, I'm pretty sure this is a stupid question. Nevertheless I had no idea where else I could find any help.

I've followed the install instructions and installed + activated the blade plugin: http://prntscr.com/2u0x1u

Next thing I did was making sure the views folder is writable by setting the chmod to 777.

According to http://wordpress.org/plugins/blade/installation/ I should now be able to use blade syntax.

Next thing I did was add the following lines to a working wp template file: http://prntscr.com/2u0xwu

The output is: http://prntscr.com/2u0y9x

As you can see, it's not parsing the template engine.
The page renders {{$helloWorld}}

Do you have any idea what I am missing? Since I realy appreciate bringing a template engine into wordpress, especially when it's based on Razor, ofwhich I have years of experience.

Thanks

.

please delete.

Blade in WordPress

How to implement in wordpress?
i have created a plugin Cities in which we will have the details about any city we add to it. it was generated with WP MVC and its working properly. Now i need to implement blade in wordpress.

i have installed blade plugin in wordpress and have activated it. i have renamed some files to .blade.php say for ex. add.blade.php. when i happen to execute this particular file, it gives a warning message followed by an error message and the action is not done.

[MVC] Warning: View "admin/add" not found.
Thrown on line 204 of /var/www/html/wordpress/wp-content/plugins/wp-mvc/core/controllers/mvc_controller.php

( ! ) Warning: require(): Filename cannot be empty in /var/www/html/wordpress/wp-content/plugins/wp-mvc/core/controllers/mvc_controller.php on line 265

( ! ) Fatal error: require(): Failed opening required '' (include_path='.:/usr/share/php:/usr/share/pear') in /var/www/html/wordpress/wp-content/plugins/wp-mvc/core/controllers/mvc_controller.php on line 265

Could you please help me in this regard?

Allow .blade.php extension

Hi, would it be possible to allow including files named .blade.php instead of just .php? Or is that not possible?

How to use it in a Widget

Hi,

First of all: Hallelujah!
Blade is such a great engine and we love to work with it!

Being able to use Blade in Wordpress is the best!

I do have a about using it in a widget.
Is there someway to include the engine in a widget?

My {{ }} are not being replaced right now!

v0.3.7

Could you please set v0.3.7 as tag version on the latest commit and not 0.3.7 only? Thanks!

->render() not evaluating Blade syntax

I could not find an existing issue, and I could not find that I'm using incorrect syntax. When I want to have a template rendered manually to output, in this case for an Ajax-request, I would assume the following would work:

$content = view('name-of-template')->render();

It does however not evaluate Blade-syntax like {{ 'Foo' }}. The $content contains the literal string {{ 'Foo' }}.

I did use a hacky way to get it rendered properly:

$model = \WP_Blade_Main_Model::make();
$absolute_path = get_template_directory().'/name-of-template.php';
$rendered_path = $model->template_include_blade($absolute_path);
include($rendered_path);

This seems however not exactly the best approach. Am I right in assuming ->render() should work in this situation?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.