PHPackages                             vivait/twig-safe-date - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. vivait/twig-safe-date

ActiveLibrary[Templating &amp; Views](/categories/templating)

vivait/twig-safe-date
=====================

A safe date function in twig that will not set null dates to today.

2.0(9mo ago)026.7k↓21.9%[1 PRs](https://github.com/vivait/twig-safe-date/pulls)MITPHPPHP &gt;=8.3CI passing

Since Oct 27Pushed 5mo ago1 watchersCompare

[ Source](https://github.com/vivait/twig-safe-date)[ Packagist](https://packagist.org/packages/vivait/twig-safe-date)[ RSS](/packages/vivait-twig-safe-date/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (4)Versions (5)Used By (0)

Twig Safe Date Extension
========================

[](#twig-safe-date-extension)

Simple filter in twig to help avoid problems with things like: `{{ null|date('Y-m-d') }}`

There are ways around it using twig - the [documentation](https://twig.symfony.com/doc/2.x/filters/date.html) even states:

> If the value passed to the date filter is null, it will return the current date by default. If an empty string is desired instead of the current date, use a ternary operator:
>
> `{{ post.published_at is empty ? "" : post.published_at|date("m/d/Y") }}`

But often, this is overlooked leading to erroneous information being displayed.

Requirements
------------

[](#requirements)

- PHP = ^8.3
- Twig ^3.10

Installation &amp; Usage
------------------------

[](#installation--usage)

`composer require vivait/twig-safe-date`

Once required, register the extension with Twig:

```
$twig = new \Twig_Environment($loader);
$twig->addExtension(new TwigSafeDateExtension);
```

Once registered, you can use the filter `date` to output dates as before, with the change that: **null values will get turned into known content (default: `-`) rather than today's date**

The default format is `'F j, Y H:i.'` (the same as the core `date` filter in Twig)

```
{{ post.posted_at|date }}

```

If you wish to change the format of the date, pass it a parameter with your preferred format:

```
{{ post.posted_at|date("d/m/Y") }}

```

If `post.posted_at` is `null`, then by default the filter will output `-`, if you wish to change this to a different value, pass a new default as the third parameter:

```
{{ post.posted_at|date("d/m/Y", "Europe/London" "Content if null") }}

```

###  Health Score

50

—

FairBetter than 96% of packages

Maintenance66

Regular maintenance activity

Popularity26

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity81

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 82.4% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~1426 days

Total

3

Last Release

272d ago

Major Versions

0.1 → 1.02022-06-23

1.0 → 2.02025-08-20

PHP version history (3 changes)0.1PHP &gt;=7.0

1.0PHP &gt;=7.4

2.0PHP &gt;=8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/e951e64fe319138045c10cf13c76e276a68b3ee4416acb58c4fd2be4e7af0040?d=identicon)[kieljohn](/maintainers/kieljohn)

---

Top Contributors

[![kieljohn](https://avatars.githubusercontent.com/u/1641880?v=4)](https://github.com/kieljohn "kieljohn (14 commits)")[![Brunty](https://avatars.githubusercontent.com/u/1573273?v=4)](https://github.com/Brunty "Brunty (1 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")[![leightonthomas](https://avatars.githubusercontent.com/u/14091070?v=4)](https://github.com/leightonthomas "leightonthomas (1 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/vivait-twig-safe-date/health.svg)

```
[![Health](https://phpackages.com/badges/vivait-twig-safe-date/health.svg)](https://phpackages.com/packages/vivait-twig-safe-date)
```

###  Alternatives

[twig/extra-bundle

A Symfony bundle for extra Twig extensions

91492.0M315](/packages/twig-extra-bundle)[twig/intl-extra

A Twig extension for Intl

36763.2M221](/packages/twig-intl-extra)[rcrowe/twigbridge

Adds the power of Twig to Laravel

9105.9M50](/packages/rcrowe-twigbridge)[twig/string-extra

A Twig extension for Symfony String

22046.0M133](/packages/twig-string-extra)[twig/cssinliner-extra

A Twig extension to allow inlining CSS

22918.5M55](/packages/twig-cssinliner-extra)[symfony/ux-twig-component

Twig components for Symfony

21914.8M162](/packages/symfony-ux-twig-component)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
