Git Product home page Git Product logo

grav-plugin-twig-extensions's Introduction

Twig Extensions Plugin

Abandonment Notice: I'm afraid I simply don't have the time to maintain my Grav themes and plugins. Those interested in taking over should refer to the "Abandoned Resource Protocol". Feel free to fork and replace. So long, and thanks for all the fish.

The Twig Extensions plugin is for Grav CMS. It pulls in a subset of the official Twig Extensions, v1.4.0.

For a demo, visit my blog.

Installation

Installing the Twig Extensions plugin can be done in one of two ways. The GPM (Grav Package Manager) installation method enables you to quickly and easily install the plugin with a simple terminal command, while the manual method enables you to do so via a zip file.

GPM Installation (Preferred)

The simplest way to install this plugin is via the Grav Package Manager (GPM) through your system's terminal (also called the command line). From the root of your Grav install type:

bin/gpm install twig-extensions

This will install the Twig Extensions plugin into your /user/plugins directory within Grav. Its files can be found under /your/site/grav/user/plugins/twig-extensions.

Manual Installation

To install this plugin, just download the zip version of this repository and unzip it under /your/site/grav/user/plugins. Then, rename the folder to twig-extensions. You can find these files on GitHub or via GetGrav.org.

You should now have all the plugin files under

/your/site/grav/user/plugins/twig-extensions

NOTE: This plugin is a modular component for Grav which requires Grav and the Error and Problems to operate.

Configuration

Below is the default configuration. An explanation of the various fields follows. To customize, first copy twig-extensions.yaml to your user/config/plugins folder and edit that copy.

enabled: true
modules: [array, intl, date]

  • The enabled field turns the plugin off and on.

  • The modules array tells the plugin which modules you want imported. This plugin only imports three of the five modules. These are the only valid options.

Usage

Simply enable the plugin to use these Twig filters. There are three modules available:

  • The Intl module provides three filters:

    • localizeddate formats a date based on the locale.
    • localizednumber formats a number based on the locale.
    • localizedcurrency formats a number based on a given currency code.
  • The Array module provides a single filter:

    • shuffle randomizes an array.
    • Note: This code was slightly modified to allow shuffling associative arrays. Simply pass true to enable this feature: {{ myArray | shuffle(true) }}.

The Date module also only provides a single filter:

  • time_diff dispays the delta between two dates in a human readable form (e.g., 2 days ago).

For more information, read the official documentation.

Omitted Modules

  • The Text module is omitted because Grav already has truncate built in, and the wordwrap provided here is not very helpful.

  • The I18n module is omitted because Grav already has extensive i18n features.

grav-plugin-twig-extensions's People

Contributors

lamecarlate avatar morremeyer avatar perlkonig avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

grav-plugin-twig-extensions's Issues

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.