diff --git a/view/SSViewer.php b/view/SSViewer.php index 8ae373881..3716e0986 100644 --- a/view/SSViewer.php +++ b/view/SSViewer.php @@ -786,7 +786,9 @@ class SSViewer implements Flushable { * </code> */ public function __construct($templateList, TemplateParser $parser = null) { - $this->setParser($parser ?: Injector::inst()->get('SSTemplateParser')); + if ($parser) { + $this->setParser($parser); + } if(!is_array($templateList) && substr((string) $templateList,-3) == '.ss') { $this->chosenTemplates['main'] = $templateList; @@ -830,6 +832,9 @@ class SSViewer implements Flushable { */ public function getParser() { + if (!$this->parser) { + $this->setParser(Injector::inst()->get('SSTemplateParser')); + } return $this->parser; } @@ -1106,9 +1111,11 @@ class SSViewer implements Flushable { // through $Content and $Layout placeholders. foreach(array('Content', 'Layout') as $subtemplate) { if(isset($this->chosenTemplates[$subtemplate])) { - $subtemplateViewer = new SSViewer($this->chosenTemplates[$subtemplate], $this->parser); + $subtemplateViewer = clone $this; + // Disable requirements - this will be handled by the parent template $subtemplateViewer->includeRequirements(false); - $subtemplateViewer->setPartialCacheStore($this->getPartialCacheStore()); + // The subtemplate is the only file we want to process, so set it as the "main" template file + $subtemplateViewer->chosenTemplates = array('main' => $this->chosenTemplates[$subtemplate]); $underlay[$subtemplate] = $subtemplateViewer->process($item, $arguments); } @@ -1174,7 +1181,7 @@ class SSViewer implements Flushable { } public function parseTemplateContent($content, $template="") { - return $this->parser->compileString( + return $this->getParser()->compileString( $content, $template, Director::isDev() && Config::inst()->get('SSViewer', 'source_file_comments') @@ -1243,7 +1250,10 @@ class SSViewer_FromString extends SSViewer { protected $cacheTemplate; public function __construct($content, TemplateParser $parser = null) { - $this->setParser($parser ?: Injector::inst()->get('SSTemplateParser')); + if ($parser) { + $this->setParser($parser); + } + $this->content = $content; }