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

Modifier doesn't accept parameter #2505

Closed
aerni opened this issue Sep 23, 2020 · 3 comments · Fixed by #4257
Closed

Modifier doesn't accept parameter #2505

aerni opened this issue Sep 23, 2020 · 3 comments · Fixed by #4257

Comments

@aerni
Copy link
Contributor

aerni commented Sep 23, 2020

Bug Description

I'm trying to pass {{ site:short_locale }} as a parameter to a custom modifier. Is this even supposed to work?

The modifier $params in this example is null:

{{ title :translate="site:short_locale" }}

The modifier $params in this example is {site:short_locale}:

{{ title translate="{site:short_locale}" }}

How to Reproduce

Create a modifier and try to pass the parameter like in the example above.

Environment

Statamic 3.0.12 Pro
Laravel 7.28.3
PHP 7.4.9
aerni/translator dev-feature/statamic-v3

@jasonvarga
Copy link
Member

The : prefix only works for tags, not modifiers.

In a modifier we'd manually see if the value (ie. the string "site:short_locale") exists in the context, and if not we fall back the literal.

However this is pretty inconsistent, so maybe it should just work like you're expecting.

@aerni
Copy link
Contributor Author

aerni commented Oct 2, 2020

That'd be a great enhancement.

Summary

I'm expecting variables to parse before they are passed to the modifier. The same way it already works with tags.

Example

Modifier syntax:

{{ title :translate="site:short_locale" }}

or

{{ title translate="{site:short_locale}" }}

site:short_locale should parse to en. This is in config/sites.php:

'sites' => [

  'default' => [
    'name' => 'English',
    'locale' => 'en_US',
    'url' => '/',
  ],

]

@github-actions github-actions bot added the stale label Jan 17, 2021
@aerni
Copy link
Contributor Author

aerni commented Jan 18, 2021

Still a great enhancement idea.

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

Successfully merging a pull request may close this issue.

3 participants