Remove the use of Twig_Loader_String, added Twig::parse

This commit is contained in:
Samuel Georges 2015-09-30 05:26:00 +10:00
parent dd6e0a3836
commit bbfba7dc34
4 changed files with 15 additions and 20 deletions

View File

@ -1,3 +1,6 @@
* **Build 300** (2015-10-xx)
- Added new helper `Twig::parse` for parsing Twig.
* **Build 298** (2015-09-24) * **Build 298** (2015-09-24)
- Added the ability to use a wildcard URL parameter in CMS pages (see CMS > Pages docs). - Added the ability to use a wildcard URL parameter in CMS pages (see CMS > Pages docs).

View File

@ -257,10 +257,10 @@ class ServiceProvider extends ModuleServiceProvider
protected function registerTwigParser() protected function registerTwigParser()
{ {
/* /*
* Register basic Twig * Register system Twig environment
*/ */
App::singleton('twig', function ($app) { App::singleton('twig.environment', function ($app) {
$twig = new Twig_Environment(new TwigLoader(), ['auto_reload' => true]); $twig = new Twig_Environment(new TwigLoader, ['auto_reload' => true]);
$twig->addExtension(new TwigExtension); $twig->addExtension(new TwigExtension);
return $twig; return $twig;
}); });
@ -269,16 +269,7 @@ class ServiceProvider extends ModuleServiceProvider
* Register .htm extension for Twig views * Register .htm extension for Twig views
*/ */
App::make('view')->addExtension('htm', 'twig', function () { App::make('view')->addExtension('htm', 'twig', function () {
return new TwigEngine(App::make('twig')); return new TwigEngine(App::make('twig.environment'));
});
/*
* Register Twig that will parse strings
*/
App::singleton('twig.string', function ($app) {
$twig = $app['twig'];
$twig->setLoader(new Twig_Loader_String);
return $twig;
}); });
} }

View File

@ -51,6 +51,7 @@ return [
'Str' => 'October\Rain\Support\Facades\Str', 'Str' => 'October\Rain\Support\Facades\Str',
'Markdown' => 'October\Rain\Support\Facades\Markdown', 'Markdown' => 'October\Rain\Support\Facades\Markdown',
'Yaml' => 'October\Rain\Support\Facades\Yaml', 'Yaml' => 'October\Rain\Support\Facades\Yaml',
'Twig' => 'October\Rain\Support\Facades\Twig',
'DbDongle' => 'October\Rain\Support\Facades\DbDongle', 'DbDongle' => 'October\Rain\Support\Facades\DbDongle',
'Backend' => 'Backend\Facades\Backend', 'Backend' => 'Backend\Facades\Backend',
'BackendMenu' => 'Backend\Facades\BackendMenu', 'BackendMenu' => 'Backend\Facades\BackendMenu',

View File

@ -2,6 +2,7 @@
use App; use App;
use File; use File;
use Twig;
use View; use View;
use Model; use Model;
use October\Rain\Mail\MailParser; use October\Rain\Mail\MailParser;
@ -130,17 +131,16 @@ class MailTemplate extends Model
} }
/* /*
* Get Twig to load from a string * Subject
*/ */
$twig = App::make('twig.string'); $message->subject(Twig::parse($template->subject, $data));
$message->subject($twig->render($template->subject, $data));
/* /*
* HTML contents * HTML contents
*/ */
$html = $twig->render($template->content_html, $data); $html = Twig::parse($template->content_html, $data);
if ($template->layout) { if ($template->layout) {
$html = $twig->render($template->layout->content_html, [ $html = Twig::parse($template->layout->content_html, [
'content' => $html, 'content' => $html,
'css' => $template->layout->content_css 'css' => $template->layout->content_css
] + (array) $data); ] + (array) $data);
@ -152,9 +152,9 @@ class MailTemplate extends Model
* Text contents * Text contents
*/ */
if (strlen($template->content_text)) { if (strlen($template->content_text)) {
$text = $twig->render($template->content_text, $data); $text = Twig::parse($template->content_text, $data);
if ($template->layout) { if ($template->layout) {
$text = $twig->render($template->layout->content_text, [ $text = Twig::parse($template->layout->content_text, [
'content' => $text 'content' => $text
] + (array) $data); ] + (array) $data);
} }