Skip to content
Permalink
Browse files

ENHANCEMENT Allow <% include %> to fallback outside of the Includes f…

…older

Fixes #7108
  • Loading branch information
Damian Mooyman
Damian Mooyman committed Aug 29, 2017
1 parent 34aede5 commit 98c10b089c0c3a9315f075dc44ab46bbe361369a
@@ -891,7 +891,7 @@ class SSTemplateParser extends Parser implements TemplateParser
$template = $res['template'];
$arguments = $res['arguments'];

$res['php'] = '$val .= \\SilverStripe\\View\\SSViewer::execute_template(["type" => "Includes", '.$template.'], $scope->getItem(), array(' .
$res['php'] = '$val .= \\SilverStripe\\View\\SSViewer::execute_template([["type" => "Includes", '.$template.'], '.$template.'], $scope->getItem(), array(' .
implode(',', $arguments)."), \$scope);\n";

if ($this->includeDebuggingComments) { // Add include filename comments on dev sites
@@ -3499,7 +3499,7 @@ function Include__finalise(&$res)
$template = $res['template'];
$arguments = $res['arguments'];
$res['php'] = '$val .= \\SilverStripe\\View\\SSViewer::execute_template(["type" => "Includes", '.$template.'], $scope->getItem(), array(' .
$res['php'] = '$val .= \\SilverStripe\\View\\SSViewer::execute_template([["type" => "Includes", '.$template.'], '.$template.'], $scope->getItem(), array(' .
implode(',', $arguments)."), \$scope);\n";
if ($this->includeDebuggingComments) { // Add include filename comments on dev sites
@@ -1055,13 +1055,44 @@ public function testNamespaceInclude()
'Backslashes work for namespace references in includes'
);
$this->assertEquals(
"tests:( NamespaceInclude\n )",
$this->render('tests:( <% include Namespace\\NamespaceInclude %> )', $data),
'Escaped backslashes work for namespace references in includes'
);
$this->assertEquals(
"tests:( NamespaceInclude\n )",
$this->render('tests:( <% include Namespace/NamespaceInclude %> )', $data),
'Forward slashes work for namespace references in includes'
);
}
/**
* Test search for includes fallback to non-includes folder
*/
public function testIncludeFallbacks()
{
$data = new ArrayData([]);
$this->assertEquals(
"tests:( Namespace/Includes/IncludedTwice.ss\n )",
$this->render('tests:( <% include Namespace\\IncludedTwice %> )', $data),
'Prefer Includes in the Includes folder'
);
$this->assertEquals(
"tests:( Namespace/Includes/IncludedOnceSub.ss\n )",
$this->render('tests:( <% include Namespace\\IncludedOnceSub %> )', $data),
'Includes in only Includes folder can be found'
);
$this->assertEquals(
"tests:( Namespace/IncludedOnceBase.ss\n )",
$this->render('tests:( <% include Namespace\\IncludedOnceBase %> )', $data),
'Includes outside of Includes folder can be found'
);
}
public function testRecursiveInclude()
{
@@ -0,0 +1 @@
Namespace/IncludedOnceBase.ss
@@ -0,0 +1 @@
Namespace/IncludedTwice.ss
@@ -0,0 +1 @@
Namespace/Includes/IncludedOnceSub.ss
@@ -0,0 +1 @@
Namespace/Includes/IncludedTwice.ss

0 comments on commit 98c10b0

Please sign in to comment.
You can’t perform that action at this time.