mirror of
https://github.com/espocrm/espocrm.git
synced 2026-06-28 06:56:05 +00:00
htmlizer fix iterate and test
This commit is contained in:
@@ -919,6 +919,11 @@ class Htmlizer
|
||||
|
||||
$newTemplate = str_replace('</iteration-wrapper>', '{{/each}}', $newTemplate);
|
||||
|
||||
$from = strpos($newTemplate,'<body>') + 6;
|
||||
$to = strrpos($newTemplate, '</body>') - strlen($newTemplate);
|
||||
|
||||
$newTemplate = substr($newTemplate, $from, $to);
|
||||
|
||||
return preg_replace('/<iteration-wrapper v="{{(.*)}}">/', '{{#each $1}}', $newTemplate) ?? '';
|
||||
}
|
||||
|
||||
|
||||
@@ -223,4 +223,22 @@ class HtmlizerTest extends TestCase
|
||||
$html = $this->htmlizer->render($entity, $template);
|
||||
$this->assertEquals('test', $html);
|
||||
}
|
||||
|
||||
public function testIterate(): void
|
||||
{
|
||||
/** @noinspection HtmlUnknownAttribute */
|
||||
$template = "<ul><li iterate=\"{{items}}\">{{name}}</li></ul>";
|
||||
|
||||
$html = $this->htmlizer->render(null, $template, null, [
|
||||
'items' => [
|
||||
['name' => '1'],
|
||||
['name' => '2'],
|
||||
],
|
||||
]);
|
||||
|
||||
/** @noinspection HtmlUnknownAttribute */
|
||||
$expected = "<ul><li>1</li><li>2</li></ul>";
|
||||
|
||||
$this->assertEquals($expected, $html);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user