diff --git a/bladerunner.php b/bladerunner.php index 692c2bc..6499d8b 100644 --- a/bladerunner.php +++ b/bladerunner.php @@ -3,7 +3,7 @@ Plugin Name: Bladerunner Plugin URI: http://bladerunner.aekab.se Description: Laravel Blade template engine for WordPress -Version: 1.0.7 +Version: 1.0.8 Author: Andreas Ek Author URI: http://www.aekab.se/ License: MIT License @@ -25,3 +25,21 @@ register_activation_hook(__FILE__, '\Bladerunner\init::createCacheDirectory'); register_deactivation_hook(__FILE__, '\Bladerunner\init::deleteCacheDirectory'); + +/** + * Check if global helper function could be declared + */ +if (!function_exists('bladerunner')) { + /** + * Global helper function to use in templates to render correct view + * This will use the Illuminate Blade engine to render correct view in a standard WordPress template + * @param string $view Name of the view with path, eg: views.pages.single + * @param array $data Any object data to use in the view template/file + * @return void + */ + function bladerunner($view, $data = []) + { + $blade = new \Bladerunner\Blade(get_stylesheet_directory(), \Bladerunner\Cache::path()); + echo $blade->view()->make($view, $data)->render(); + } +} diff --git a/composer.json b/composer.json index 8d00b9b..df70039 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "ekandreas/bladerunner", "type": "wordpress-plugin", - "version": "1.0.7", + "version": "1.0.8", "description": "WordPress Blade L5 template engine", "keywords": ["laravel", "blade", "wordpress"], "license": "MIT", diff --git a/readme.md b/readme.md index 778d398..7458662 100644 --- a/readme.md +++ b/readme.md @@ -1,6 +1,6 @@ # Bladerunner -[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://packagist.org/packages/ekandreas/bladerunner) +[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/ekandreas/bladerunner) [![Build Status](https://travis-ci.org/ekandreas/bladerunner.svg?branch=master)](https://travis-ci.org/ekandreas/bladerunner) [![StyleCI](https://styleci.io/repos/48002506/shield)](https://styleci.io/repos/48002506) [![GitHub release](https://img.shields.io/github/release/ekandreas/bladerunner.svg)](http://bladerunner.aekab.se/bladerunner.zip) @@ -42,6 +42,31 @@ https://laravel.com/docs/5.2/blade * Your views must be placed within your theme folder. * Your templates must have .blade.php extension. +## Template helper +There is a template helper function named "bladerunner", defined globally to use in standard WordPress templates. + +Example: +You want to create a 404-template and don't want to use the .blade.php extension to the template file. + +* Create a 404.php in the theme root. +* Add the following code to the template: +``` +$module]); +``` +or use compact, eg: +``` +