Add support for a null-safe filter operator ?|
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 8.4k
- Forks
- 1.3k
- Avg merge
- 1d 13h
- Merged PRs (30d)
- 37
Description
My twig templates are full of code where I have a parameter, usually a date, that I need to display if it exists:
{{ site.startDate ? site.startDate|date('m/d/Y') }}
It would be nice if this could be shortened to something like this:
{{ site.startDate ?| date('m/d/Y') }}
I know that I could just write a a custom date filter that handles null input, along the lines of below, but this seems a bit much:
#[AsTwigFilter(name: 'safe_date', needsEnvironment: true)]
public function safeDate(Environment $env, $date, ?string $format = null, $timezone = null): string
{
if (empty($date)) {
return '';
}
return $env->getExtension(CoreExtension::class)->formatDate($date, $format, $timezone);
}
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No file, test, or entry point is named in the issue. Start by locating Twig's expression and filter syntax handling, then define and test the proposed null-safe ?| behavior using the examples; done means null values are handled as requested without breaking existing filter syntax.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- web-dev
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100