Skip to content
This repository has been archived by the owner on Jun 9, 2022. It is now read-only.

Perlkonig/grav-plugin-twig-jasny-array

Repository files navigation

Twig Jasny Array 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 Jasny Array plugin is for Grav CMS. It incorporates the Array module from Jasny's Twig extensions.

For a demo, visit my blog.

Installation

Installing the Twig Jasny Array 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-jasny-array

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

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-jasny-array. 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-jasny-array

Configuration

The config consists of the single enabled field, which turns the plugin off and on.

Usage

This plugin only incorporates the Array module from Jasny's Twig extensions. The other modules duplicate functionality found in the Twig Extensions and Twig PCRE plugins.

It exposes the following filters:

  • sum – calculates the sum of the values in an array
  • product – calculates the product of the values in an array
  • values – returns all the values of an array
  • as_array – casts an object to an associative array
  • html_attr – turns an array into an HTML attribute string (i.e. $key="$value")