Merge pull request #7322 from open-sausages/pulls/4.0/allow-external-includes

ENHANCEMENT Allow <% include %> to fallback outside of the Includes folder
This commit is contained in:
Chris Joe 2017-08-29 16:48:58 +12:00 committed by GitHub
commit b2c4b7123e
7 changed files with 37 additions and 2 deletions

View File

@ -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

View File

@ -3499,7 +3499,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

View File

@ -1055,6 +1055,12 @@ after'
'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),
@ -1062,6 +1068,31 @@ after'
);
}
/**
* 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()
{

View File

@ -0,0 +1 @@
Namespace/IncludedOnceBase.ss

View File

@ -0,0 +1 @@
Namespace/IncludedTwice.ss

View File

@ -0,0 +1 @@
Namespace/Includes/IncludedOnceSub.ss

View File

@ -0,0 +1 @@
Namespace/Includes/IncludedTwice.ss