Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ryanhalliday/twig-gravatar
Simple Twig extension for Gravatar Avatars
https://github.com/ryanhalliday/twig-gravatar
Last synced: 21 days ago
JSON representation
Simple Twig extension for Gravatar Avatars
- Host: GitHub
- URL: https://github.com/ryanhalliday/twig-gravatar
- Owner: ryanhalliday
- License: mit
- Created: 2015-04-13T05:42:05.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2020-01-26T21:37:47.000Z (over 4 years ago)
- Last Synced: 2024-05-19T03:04:07.330Z (28 days ago)
- Language: PHP
- Size: 28.3 KB
- Stars: 2
- Watchers: 2
- Forks: 3
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Lists
- awesome-twig - ry167Gravatar² - An extension for Twig that provides simple filters for Gravatar by [ry167](https://github.com/ry167). (Twig / Extensions)
- awesome-twig - ry167Gravatar² - An extension for Twig that provides simple filters for Gravatar by [ry167](https://github.com/ry167). (Twig / Extensions)
README
# Twig Gravatar
[![Latest Version](https://img.shields.io/github/release/ry167/twig-gravatar.svg?style=flat-square)](https://github.com/ry167/twig-gravatar/releases)
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)
[![Build Status](https://img.shields.io/travis/ry167/twig-gravatar/master.svg?style=flat-square)](https://travis-ci.org/ry167/twig-gravatar)
[![Quality Score](https://img.shields.io/scrutinizer/g/ry167/twig-gravatar.svg?style=flat-square)](https://scrutinizer-ci.com/g/ry167/twig-gravatar)
[![Total Downloads](https://img.shields.io/packagist/dt/ry167/twig-gravatar.svg?style=flat-square)](https://packagist.org/packages/ry167/twig-gravatar)An extension for Twig that provides simple filters for Gravatar.
## Installation
Use `composer` to install this extension:
```Shell
composer require ry167/twig-gravatar 3.0.0
```## Usage
```PHP
require("vendor/autoload.php");//Define your Twig Environment and Twig Loader
$twig->addExtension(new \TwigGravatar());//or create a customized Twig Gravatar instance
new \TwigGravatar($default = null, $size = null, $filterPrefix = 'gr', $rating = null, $useHttps = true);
```## Usage in Symfony
```YAML
twig.extension.gravatar:
class: \TwigGravatar
arguments:
$default: ~ e.g. 'monsterid'
$size: ~ e.g. 50
$filterPrefix: ~ e.g. 'foo'
$rating: ~ e.g. 'x'
$useHttps: true
tags:
- { name: twig.extension }
```
You can also remove the arguments section and the default values will be used.## Filters
This Extension is designed so that you chain together the filters that you need on top of each other. You must however always start with the grAvatar filter.### grAvatar
Create a Gravatar URL, This returns just the URL for the persons avatar image without the `` tag
```Twig
{{ '[email protected]'|grAvatar }}
```### grHttps
Change a Gravatar URL to its secure counterpart.
```Twig
{{ '[email protected]'|grAvatar|grHttps }}
```### grSize
Change the Size of the Gravatar Image to the specified size in pixels.
```Twig
{{ '[email protected]'|grAvatar|grSize(1024) }}
```Gravatar does not serve images greater than `2048px`, and they are all squares.
### grDefault
Specify a default image for if the User does not have one defined
```Twig
{{ '[email protected]'|grAvatar|grDefault('http://example.com/default.png') }}
```You can also use any of Gravatar's built in default images, [you can see them here](http://en.gravatar.com/site/implement/images/#default-image). Just use the code assigned to them such as `mm` instead of your Image URL.
### grRating
Specify a maximum rating that the image can be.
Valid values are `g`, `pg`, `r` and `x`.
```Twig
{{ '[email protected]'|grAvatar|grRating('pg') }}
```## Prefix
You can change the filter prefix from `gr` to something else by changing its value in constructor.
```PHP
//Define your Twig Environment and Twig Loader$TwigGravatar = new \TwigGravatar(null, null, 'foo');
$twig->addExtension($TwigGravatar);
//Filters are now 'fooAvatar' etc
```