Skip to content

Commit

Permalink
No stop at no template found
Browse files Browse the repository at this point in the history
Filters changed
Data to template added as filter
  • Loading branch information
Andreas Ek committed Jan 22, 2016
1 parent 9add0b2 commit 2477471
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 27 deletions.
2 changes: 1 addition & 1 deletion bladerunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Plugin Name: Bladerunner
Plugin URI: http://bladerunner.aekab.se
Description: Laravel Blade template engine for WordPress
Version: 1.0.4
Version: 1.0.5
Author: Andreas Ek
Author URI: http://www.aekab.se/
License: MIT License
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ekandreas/bladerunner",
"type": "wordpress-plugin",
"version": "1.0.4",
"version": "1.0.5",
"description": "WordPress Blade L5 template engine",
"keywords": ["laravel", "blade", "wordpress"],
"license": "MIT",
Expand Down
4 changes: 0 additions & 4 deletions deploy.php

This file was deleted.

11 changes: 8 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,19 @@ https://laravel.com/docs/5.2/blade
## Pass data to template
A simple way to pass data to a view before it's loaded.

Run the below code (and change variableName and $value) before the template_include filter (or in the template_include filter with higher priority than 999) to pass data to the soon to be loaded view.
Set the filter ``bladerunner/templates/data`` before running a template to pass custom data to the template, eg:
```
\Bladerunner\Template::$data['variableName'] = $value;
$data = [
'this' => 'that',
'other' => 'perhaps',
];
add_filter('bladerunner/templates/data', compact('data'));
```

Inside your view file you will be able to access the passed data like so:
```
{{ $variableName }}
{{ $data['this'] }}
{{ $data['other'] }}
```

## Hooks & Filters
Expand Down
2 changes: 1 addition & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Contributors: ekandreas
Tags: Blade,templates,development,laravel
Requires at least: 4.4
Tested up to: 4.4
Stable tag: 1.0.4
Stable tag: 1.0.5
License: MIT

WordPress plugin for Blade L5 templating
Expand Down
27 changes: 10 additions & 17 deletions src/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,16 @@ class Template
*
* @var array
*/
public static $data = array();
public $data = [];

/**
* Constructor.
*/
public function __construct()
{
add_filter('template_include', [$this, 'path'], 999);
add_action('template_redirect', [$this, 'init']);
}

/**
* Adding {$type}_template to WP
*/
public function init()
{
$this->addTemplateFilters();
add_filter('template_include', [$this, 'templateFilter'], 999);
add_action('template_redirect', [$this, 'addPageTemplateFilters']);
$this->data = apply_filters('bladerunner/templates/data', [] );
}

/**
Expand All @@ -43,21 +36,21 @@ public function init()
*
* @return string
*/
public function path($template)
public function templateFilter($template)
{
$path = $template;

if (!$template) {
return $path;
}

$template = apply_filters('bladerunner/get_post_template', $template);
$template = apply_filters('bladerunner/template/post', $template);

$views = get_stylesheet_directory();

$cache = self::cache();
if (!file_exists($cache)) {
throw new \Exception('Bladerunner: Cache folder does not exist.');
trigger_error("Bladerunner: Cache folder {$cache} does not exist.", E_WARNING);
return $template;
}

Expand All @@ -72,7 +65,7 @@ public function path($template)
}

if (!file_exists($template)) {
throw new \Exception("Bladerunner: Missing template file {$template}");
trigger_error("Bladerunner: Missing template file {$template}", E_WARNING);
return $template;
}

Expand Down Expand Up @@ -109,7 +102,7 @@ public static function cache()
/**
* Add template filters.
*/
private function addTemplateFilters()
public function addPageTemplateFilters()
{
$types = [
'index' => 'index.blade.php',
Expand All @@ -131,7 +124,7 @@ private function addTemplateFilters()
'attachment' => 'attachment.blade.php',
];

$types = apply_filters('bladerunner/template_types', $types);
$types = apply_filters('bladerunner/template/types', $types);

if ($types) {
foreach ($types as $key => $type) {
Expand Down

0 comments on commit 2477471

Please sign in to comment.