Git Product home page Git Product logo

craft-timediff's Introduction

Craft Time Diff

Craft Time Diff brings in the Twig Date Extension.

Installation

  • Place the timediff folder inside your craft/plugins/ folder.
  • Go to settings/plugins and install timediff

Usage

The plugin adds the Twig time_diff filter (http://twig.sensiolabs.org/doc/extensions/date.html).

Time Diff

Renders the difference between a date and now:

{{ post.published_at|time_diff }}

Outputs "1 day ago" or "in 5 months"

Translations

Need to translate into other languages? Version 1.1 adds a simplistic delimited string that can be split into an array, and uses Craft's built-in translation string where available:

{{ post.published_at|time_diff_array }}

Outputs "past|1|day|singular" or "future|5|month|plural"

This could then be turned into an array with Twig's split filter:

{% set diffArray = post.published_at|time_diff_array|split('|') %}

The array's first element will be either the word "past" or "future" (not translated), the second element is the number of units, the third is the unit name (translated if available), and the last is the word "plural" or "singular".

Credits

  • SensioLabs for writing the Date Extension

craft-timediff's People

Contributors

mildlygeeky avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

craft-timediff's Issues

Craft 3

Hey there, this is one of my favourite plugins to use with Craft! Just wondering, are there any plans to update it for use with Craft 3?

Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.