mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
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:
commit
b2c4b7123e
@ -891,7 +891,7 @@ class SSTemplateParser extends Parser implements TemplateParser
|
|||||||
$template = $res['template'];
|
$template = $res['template'];
|
||||||
$arguments = $res['arguments'];
|
$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";
|
implode(',', $arguments)."), \$scope);\n";
|
||||||
|
|
||||||
if ($this->includeDebuggingComments) { // Add include filename comments on dev sites
|
if ($this->includeDebuggingComments) { // Add include filename comments on dev sites
|
||||||
|
@ -3499,7 +3499,7 @@ class SSTemplateParser extends Parser implements TemplateParser
|
|||||||
$template = $res['template'];
|
$template = $res['template'];
|
||||||
$arguments = $res['arguments'];
|
$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";
|
implode(',', $arguments)."), \$scope);\n";
|
||||||
|
|
||||||
if ($this->includeDebuggingComments) { // Add include filename comments on dev sites
|
if ($this->includeDebuggingComments) { // Add include filename comments on dev sites
|
||||||
|
@ -1055,6 +1055,12 @@ after'
|
|||||||
'Backslashes work for namespace references in includes'
|
'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(
|
$this->assertEquals(
|
||||||
"tests:( NamespaceInclude\n )",
|
"tests:( NamespaceInclude\n )",
|
||||||
$this->render('tests:( <% include Namespace/NamespaceInclude %> )', $data),
|
$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()
|
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
|
Loading…
Reference in New Issue
Block a user