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

Null Coalescence doesn't return fallback if falsey variable uses a modifier #2022

Closed
richarderoche opened this issue Jul 2, 2020 · 6 comments
Labels

Comments

@richarderoche
Copy link

Bug Description

When using ?? or "or" to display a variable with a fallback it comes back blank if the first variable is null and has a modifier applied to it, even if the fallback variable is not null. However, Ternary format does work as expected.

How to Reproduce

Create something like this with the first variable being a null one and the second one existing, it will return nothing:
{{alt_title|upper ?? title|upper}}

This will return the title variable (as expected):
{{alt_title ?? title}}

This will return the title variable in uppercase (as expected):
{{alt_title ? alt_title|upper : title|upper}}

Extra Detail

Environment

Statamic version: 3.0.0.-beta-33

PHP version: 7.4

Install method (choose one):

  • Fresh install from statamic/statamic
@ReneWeCode
Copy link
Contributor

Confirms. I was struggling for a long time with this one: {{ title_override ?? title ensure_right=">" }}

@jackmcdade
Copy link
Member

Confirmed. Will see what I can do!

Weirdly enough, the issue seems more related to the > than the modifier itself. This works (alt syntax):

{{ title_override ?? title | ensure_right:.com }}

@jasonvarga
Copy link
Member

Unfortunately, we have to revert the change we made as we noticed it introduced unrelated issues. We'll get back to this though!

@github-actions
Copy link

github-actions bot commented Jan 7, 2021

This issue has not had recent activity and has been marked as stale — by me, a robot. Simply reply to keep it open and send me away. If you do nothing, I will close it in a week. I have no feelings, so whatever you do is fine by me.

@github-actions github-actions bot added the stale label Jan 7, 2021
@jelleroorda
Copy link
Contributor

Open sesame

@github-actions github-actions bot removed the stale label Jan 13, 2021
cnc137 added a commit to cnc137/starter-kit-cool-writings that referenced this issue Feb 22, 2021
Fixes problem where if "excerpt" is blank, the first 160 characters of "content" are not displayed. This is related to "Null Coalescence doesn't return fallback if falsey variable uses a modifier #2022" issue located at statamic/cms#2022
@cnc137
Copy link

cnc137 commented Feb 22, 2021

I ran across this problem in the "Cool Writings" starter kit ( https://github.com/statamic/starter-kit-cool-writings ) if the "excerpt" is blank since the code uses the "widont" modifier. I submitted a pull request, mentioned above, to solve the problem in the starter kit based on the information provided above.

jackmcdade pushed a commit to statamic/starter-kit-cool-writings that referenced this issue Feb 22, 2021
Fixes problem where if "excerpt" is blank, the first 160 characters of "content" are not displayed. This is related to "Null Coalescence doesn't return fallback if falsey variable uses a modifier #2022" issue located at statamic/cms#2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants