ry167/twig-gravatar
最新稳定版本:4.0.0-RC
Composer 安装命令:
composer require ry167/twig-gravatar
包简介
Gravatar filters for Twig templates
关键字:
README 文档
README
An extension for Twig that provides simple filters for Gravatar.
Installation
Use composer to install this extension:
composer require ry167/twig-gravatar 3.0.0
Usage
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
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 <img> tag
{{ 'example@example.com'|grAvatar }}
grHttps
Change a Gravatar URL to its secure counterpart.
{{ 'example@example.com'|grAvatar|grHttps }}
grSize
Change the Size of the Gravatar Image to the specified size in pixels.
{{ 'example@example.com'|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
{{ 'example@example.com'|grAvatar|grDefault('http://example.com/default.png') }}
You can also use any of Gravatar's built in default images, you can see them here. 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.
{{ 'example@example.com'|grAvatar|grRating('pg') }}
Prefix
You can change the filter prefix from gr to something else by changing its value in constructor.
//Define your Twig Environment and Twig Loader $TwigGravatar = new \TwigGravatar(null, null, 'foo'); $twig->addExtension($TwigGravatar); //Filters are now 'fooAvatar' etc
统计信息
- 总下载量: 4.68k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-04-15