Skip to content

Commit

Permalink
htmplizer: ifEqual
Browse files Browse the repository at this point in the history
  • Loading branch information
yurikuzn committed Sep 14, 2017
1 parent f8523cf commit de72e6d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
20 changes: 20 additions & 0 deletions application/Espo/Core/Htmlizer/Htmlizer.php
Expand Up @@ -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']() : '';
}
}
]
]);

Expand Down
10 changes: 10 additions & 0 deletions tests/unit/Espo/Core/Htmlizer/HtmlizerTest.php
Expand Up @@ -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);
}
}

0 comments on commit de72e6d

Please sign in to comment.