Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for conditional statements #12

Open
Donnie opened this issue Aug 23, 2017 · 4 comments
Open

Support for conditional statements #12

Donnie opened this issue Aug 23, 2017 · 4 comments

Comments

@Donnie
Copy link

Donnie commented Aug 23, 2017

I have been looking for a script which would also process conditional statements in string.

for e.g:
$string = 'My name is {name} and I scored {if: score>10 then well else poorly}.

@bartlomiej84
Copy link

This would be great. Have you found a solution?

@drwxmrrs
Copy link

drwxmrrs commented Apr 18, 2018

Hoa\Ruler could help you in this circumstance :)

https://github.com/hoaproject/Ruler

@dreftymac
Copy link

@bnlab @Donnie

Conditional can be rendered using PHP

  • this approach is acceptable if the conditional can be specified in PHP
    capture

Alternatively conditional can be rendered using JMESPATH

  • this approach is acceptable if the conditional must be provided as a string
    capture

@rahal
Copy link

rahal commented Mar 13, 2023

Hi, old issue here, me too, I needed support for conditionnal and I added it : here is my pull request for this feature ( as well as some other improvements ) : #22

You can use a simple condition:

$engine = new StringTemplate\Engine();

//Returns Oh! You
$engine->render(
    'Oh! {#name}{test}{/name}',
    [
        'name' => true,
        'test' => 'You'
    ]);

You can use a simple condition with else:

$engine = new StringTemplate\Engine();

//Returns Oh! My
$engine->render(
    'Oh! {#name}{test}{#else}My{/name}',
    [
        'name' => false,
        'test' => 'You'
    ]);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants