twigphp / twigphp/Twig

Only apply filter if not null

Open
#4,389 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Investigate before 4.x
Dominant language
PHP
Stars
8.4k
Forks
1.3k
Avg merge
1d 13h
Merged PRs (30d)
37

Description

@fprochazka suggested a BC change so that the date filter returns blank instead of the current date.

Currently you have to do {{ user.birthday ? user.birthday|date('Y-m-d') : '' }} to avoid this.

Originally posted by @PrOF-kk in https://github.com/twigphp/Twig/issues/3951#issuecomment-2404415672

This got me thinking that a more generic solution would be to not apply filters to nulls, with a syntax similar to PHP's ?-> operator, like this;

 {{ user.birthday?|date('Y-m-d') }} 

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading this proposal together with the referenced discussion in issue #3951, focusing on the suggested ?| syntax and its backward-compatibility implications. The work is done when the intended null-filter behavior and syntax are resolved and implemented consistently for Twig templates.

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
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.