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

Can you pass multiple arguments to a helper / filter? #315

Open
mattbryson opened this issue Apr 12, 2017 · 1 comment
Open

Can you pass multiple arguments to a helper / filter? #315

mattbryson opened this issue Apr 12, 2017 · 1 comment

Comments

@mattbryson
Copy link

We are using mustache to parse config files, and in a few places we want a use a value if its present, else use a default value.

this can be done with...

{{# a }}{{ a }}{{/ a }}{{^ a }}{{ b }}{{/ a }}

So if A was falsey then it would use b instead. However, its getting quite verbose when we have nested properties.

{{# slide.meta.provider.some_property }}{{ slide.meta.provider.some_property }}{{/ slide.meta.provider.some_property }}{{^ slide.meta.provider.some_property }}{{ slide.default_property }}{{/ slide.meta.provider.some_property }}

I have tried to write a filter or helper method to accept 2 values, and return the first if its truthy, and the second if its not, but I cant see a way to pass multiple arguments to a filter or helper.

Is there anyway to do this?

The sudo code would end up looking something like..

    $mustache->addHelper('findValue', function ($a, $b) {
            return !empty($a) ? $a : $b;
       });
{{findValue slide.meta.provider.some_property slide.default_property}} 

Any pointers much appreciated....

@pperzyna
Copy link

@bobthecow Any news regarding this issue?

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

2 participants