mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
BUGFIX: Make SSTemplateParser work with empty templates
This commit is contained in:
parent
ce5648a700
commit
5ca97c7099
@ -3904,19 +3904,24 @@ class SSTemplateParser extends Parser {
|
||||
* @return mixed|string - The php that, when executed (via include or exec) will behave as per the template source
|
||||
*/
|
||||
static function compileString($string, $templateName = "", $includeDebuggingComments=false) {
|
||||
// Construct a parser instance
|
||||
$parser = new SSTemplateParser($string);
|
||||
$parser->includeDebuggingComments = $includeDebuggingComments;
|
||||
|
||||
// Ignore UTF8 BOM at begining of string. TODO: Confirm this is needed, make sure SSViewer handles UTF (and other encodings) properly
|
||||
if(substr($string, 0,3) == pack("CCC", 0xef, 0xbb, 0xbf)) $parser->pos = 3;
|
||||
|
||||
// Match the source against the parser
|
||||
$result = $parser->match_TopTemplate();
|
||||
if(!$result) throw new SSTemplateParseException('Unexpected problem parsing template', $parser);
|
||||
|
||||
// Get the result
|
||||
$code = $result['php'];
|
||||
if (!trim($string)) {
|
||||
$code = '';
|
||||
}
|
||||
else {
|
||||
// Construct a parser instance
|
||||
$parser = new SSTemplateParser($string);
|
||||
$parser->includeDebuggingComments = $includeDebuggingComments;
|
||||
|
||||
// Ignore UTF8 BOM at begining of string. TODO: Confirm this is needed, make sure SSViewer handles UTF (and other encodings) properly
|
||||
if(substr($string, 0,3) == pack("CCC", 0xef, 0xbb, 0xbf)) $parser->pos = 3;
|
||||
|
||||
// Match the source against the parser
|
||||
$result = $parser->match_TopTemplate();
|
||||
if(!$result) throw new SSTemplateParseException('Unexpected problem parsing template', $parser);
|
||||
|
||||
// Get the result
|
||||
$code = $result['php'];
|
||||
}
|
||||
|
||||
// Include top level debugging comments if desired
|
||||
if($includeDebuggingComments && $templateName && stripos($code, "<?xml") === false) {
|
||||
|
@ -892,19 +892,24 @@ class SSTemplateParser extends Parser {
|
||||
* @return mixed|string - The php that, when executed (via include or exec) will behave as per the template source
|
||||
*/
|
||||
static function compileString($string, $templateName = "", $includeDebuggingComments=false) {
|
||||
// Construct a parser instance
|
||||
$parser = new SSTemplateParser($string);
|
||||
$parser->includeDebuggingComments = $includeDebuggingComments;
|
||||
|
||||
// Ignore UTF8 BOM at begining of string. TODO: Confirm this is needed, make sure SSViewer handles UTF (and other encodings) properly
|
||||
if(substr($string, 0,3) == pack("CCC", 0xef, 0xbb, 0xbf)) $parser->pos = 3;
|
||||
|
||||
// Match the source against the parser
|
||||
$result = $parser->match_TopTemplate();
|
||||
if(!$result) throw new SSTemplateParseException('Unexpected problem parsing template', $parser);
|
||||
|
||||
// Get the result
|
||||
$code = $result['php'];
|
||||
if (!trim($string)) {
|
||||
$code = '';
|
||||
}
|
||||
else {
|
||||
// Construct a parser instance
|
||||
$parser = new SSTemplateParser($string);
|
||||
$parser->includeDebuggingComments = $includeDebuggingComments;
|
||||
|
||||
// Ignore UTF8 BOM at begining of string. TODO: Confirm this is needed, make sure SSViewer handles UTF (and other encodings) properly
|
||||
if(substr($string, 0,3) == pack("CCC", 0xef, 0xbb, 0xbf)) $parser->pos = 3;
|
||||
|
||||
// Match the source against the parser
|
||||
$result = $parser->match_TopTemplate();
|
||||
if(!$result) throw new SSTemplateParseException('Unexpected problem parsing template', $parser);
|
||||
|
||||
// Get the result
|
||||
$code = $result['php'];
|
||||
}
|
||||
|
||||
// Include top level debugging comments if desired
|
||||
if($includeDebuggingComments && $templateName && stripos($code, "<?xml") === false) {
|
||||
|
Loading…
Reference in New Issue
Block a user