mirror of
https://github.com/wintercms/winter.git
synced 2024-06-28 05:33:29 +02:00
Shared view vars now passed to content blocks and mail templates
This commit is contained in:
parent
649e1cfaa7
commit
0111100990
@ -20,6 +20,7 @@ use Cms\Twig\DebugExtension;
|
||||
use Cms\Twig\Extension as CmsTwigExtension;
|
||||
use Cms\Models\MaintenanceSetting;
|
||||
use System\Models\RequestLog;
|
||||
use System\Helpers\View as ViewHelper;
|
||||
use System\Classes\ErrorHandler;
|
||||
use System\Classes\CombineAssets;
|
||||
use System\Twig\Extension as SystemTwigExtension;
|
||||
@ -940,6 +941,14 @@ class Controller
|
||||
|
||||
$fileContent = $content->parsedMarkup;
|
||||
|
||||
/*
|
||||
* Inject global view variables
|
||||
*/
|
||||
$globalVars = ViewHelper::getGlobalVars();
|
||||
if (!empty($globalVars)) {
|
||||
$parameters = (array) $parameters + $globalVars;
|
||||
}
|
||||
|
||||
/*
|
||||
* Parse basic template variables
|
||||
*/
|
||||
|
30
modules/system/helpers/View.php
Normal file
30
modules/system/helpers/View.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php namespace System\Helpers;
|
||||
|
||||
use View as ViewFacade;
|
||||
|
||||
class View
|
||||
{
|
||||
/**
|
||||
* @var array Cache for global variables.
|
||||
*/
|
||||
protected static $globalVarCache;
|
||||
|
||||
/**
|
||||
* Returns shared view variables, this should be used for simple rendering cycles.
|
||||
* Such as content blocks and mail templates.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getGlobalVars()
|
||||
{
|
||||
if (static::$globalVarCache !== null) {
|
||||
return static::$globalVarCache;
|
||||
}
|
||||
|
||||
$vars = array_filter(ViewFacade::getShared(), function($var) {
|
||||
return is_scalar($var) || is_array($var);
|
||||
});
|
||||
|
||||
return static::$globalVarCache = $vars;
|
||||
}
|
||||
}
|
@ -7,6 +7,7 @@ use View;
|
||||
use Model;
|
||||
use October\Rain\Mail\MailParser;
|
||||
use System\Classes\PluginManager;
|
||||
use System\Helpers\View as ViewHelper;
|
||||
|
||||
/**
|
||||
* Mail template
|
||||
@ -141,6 +142,14 @@ class MailTemplate extends Model
|
||||
self::$cache[$code] = $template = self::findOrMakeTemplate($code);
|
||||
}
|
||||
|
||||
/*
|
||||
* Inject global view variables
|
||||
*/
|
||||
$globalVars = ViewHelper::getGlobalVars();
|
||||
if (!empty($globalVars)) {
|
||||
$data = (array) $data + $globalVars;
|
||||
}
|
||||
|
||||
/*
|
||||
* Subject
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user