Skip to content

Instantly share code, notes, and snippets.

@ekandreas
Created December 20, 2021 19:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ekandreas/0f750af15745baf7826cb2dd4d32cb56 to your computer and use it in GitHub Desktop.
Save ekandreas/0f750af15745baf7826cb2dd4d32cb56 to your computer and use it in GitHub Desktop.
Bladerunner View Plugin with BladeOne
<?php
/*
Plugin Name: Bladerunner View
Description: Replace Bladerunner with new blade view compiler
Version: 1.0.0
Author: EkAndreas
License: MIT License
*/
function bladeViewPaths()
{
$bladePaths = apply_filters('bladerunner/template/bladepath', get_stylesheet_directory());
if (!is_array($bladePaths)) {
$bladePaths = [$bladePaths];
}
$stylesheetPath = get_stylesheet_directory();
$templatePath = get_template_directory();
$bladePaths[] = $stylesheetPath . DIRECTORY_SEPARATOR . 'views';
$bladePaths[] = $stylesheetPath . DIRECTORY_SEPARATOR . 'views';
$themePaths = [
$stylesheetPath,
$stylesheetPath . DIRECTORY_SEPARATOR . 'templates',
$templatePath,
$templatePath . DIRECTORY_SEPARATOR . 'templates',
STYLESHEETPATH, // compability
STYLESHEETPATH . DIRECTORY_SEPARATOR . 'templates',
TEMPLATEPATH, // compability
TEMPLATEPATH . DIRECTORY_SEPARATOR . 'templates',
];
$bladePaths = array_merge($bladePaths, $themePaths);
$result = preg_replace('%[\/]?(templates)?[\/.]*?$%', '', $bladePaths);
$result = array_unique($result);
return $result;
}
function view($templatePath, $data = [])
{
$views = bladeViewPaths();
$cache = realpath(wp_upload_dir()['basedir'] . '/.cache');
$blade = new \eftec\bladeone\BladeOne($views, $cache, \eftec\bladeone\BladeOne::MODE_AUTO); // MODE_DEBUG allows to pinpoint troubles.
$result = $blade->run($templatePath, $data);
return $result;
}
@ekandreas
Copy link
Author

Just call for "view" inside your code.
This plugin should be placed within MU-pugins.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment