ornj / twig-extensions-bundle
Provides helpful Twig extensions for Symfony2
Installs: 363
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: >=5.3.0
- symfony/twig-bundle: ~2.1
This package is not auto-updated.
Last update: 2025-01-04 16:31:18 UTC
README
This bundle contains helpful Twig extensions for the Symfony2 framework. These extensions provide simple, front end functionality that is often times present on web pages.
Installation
Install this bundle in your Symfony2 project by adding it to your composer.json
.
{ "require": { "ornj/twig-extensions-bundle": "dev-master" } }
After running updating composer, register the bundle in app/AppKernel.php
.
$bundles = array( // ... new Ornj\Bundle\TwigExtensionsBundle\OrnjTwigExtensionsBundle(), );
Included Extensions
is_external
Determines if the url points to a host external to the current site.
Arguments
host
: Provide the host you want to check against. You can get the current host by passingapp.request.httpHost
.
{{ 'http://www.example.com' | is_external(app.request.httpHost) }}
facebook_share
Generates a url for sharing the current page on Facebook. Accepts the following parameters:
Arguments
picture
: path to an imagename
: the post titlecaption
: caption to show next to the imagedescription
: content of the postredirect
: where to send the user after they share the post
{{ url('route', { id: entity.id }) | facebook_share('http://example.com/images/img.jpg', 'name', 'caption', 'description', 'example.com/redirect) }}
In addition to the above parameters you must also provide a Facebook application id. Currently the parameter facebook_app_id
is being used. You can set the parameter however you'd like. One location this could be defined is in app/config/parameters.yml
.
pinterest_share
Generates a url for sharing the current page on Pinterest. Accepts the following parameters:
Arguments
media
: path to the media being pinneddescription
: content of the post
{{ url('route', { id: entity.id }) | pinterest_share('http://example.com/images/img.jpg', 'description') }}
twitter_share
Generates a url for sharing the current page on Twitter. Accepts a message to input into the tweet.
Arguments
message
: Body of the tweet
{{ url('route', { id: entity.id }) | twitter_share('Check out this page!') }}
To Do
- Make Facebook app id paramater a config setting instead of a parameter in parameters.yml