diff --git a/application/Espo/Core/Htmlizer/Htmlizer.php b/application/Espo/Core/Htmlizer/Htmlizer.php index a4d8aebac7..1174bb3f20 100644 --- a/application/Espo/Core/Htmlizer/Htmlizer.php +++ b/application/Espo/Core/Htmlizer/Htmlizer.php @@ -206,6 +206,26 @@ public function render(Entity $entity, $template, $id = null, $additionalData = } return ''; } + ], + 'hbhelpers' => [ + 'ifEqual' => function () { + $args = func_get_args(); + $context = $args[count($args) - 1]; + if ($args[0] === $args[1]) { + return $context['fn'](); + } else { + return $context['inverse'] ? $context['inverse']() : ''; + } + }, + 'ifNotEqual' => function () { + $args = func_get_args(); + $context = $args[count($args) - 1]; + if ($args[0] !== $args[1]) { + return $context['fn'](); + } else { + return $context['inverse'] ? $context['inverse']() : ''; + } + } ] ]); diff --git a/tests/unit/Espo/Core/Htmlizer/HtmlizerTest.php b/tests/unit/Espo/Core/Htmlizer/HtmlizerTest.php index a51bc701c6..cf8eadc683 100644 --- a/tests/unit/Espo/Core/Htmlizer/HtmlizerTest.php +++ b/tests/unit/Espo/Core/Htmlizer/HtmlizerTest.php @@ -156,6 +156,16 @@ public function testRender() $entity->set('name', '1'); $html = $this->htmlizer->render($entity, $template); $this->assertEquals('?entryPoint=attachment&id=1', $html); + + $template = "{{#ifEqual name '1'}}hello{{/ifEqual}}"; + $entity->set('name', '1'); + $html = $this->htmlizer->render($entity, $template); + $this->assertEquals('hello', $html); + + $template = "{{#ifNotEqual name '1'}}hello{{else}}test{{/ifNotEqual}}"; + $entity->set('name', '1'); + $html = $this->htmlizer->render($entity, $template); + $this->assertEquals('test', $html); } }