techwilk / twig-hashtagify
TWIG filter to turn hashtags into html links.
Installs: 1 553
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: >=7.4
- twig/twig: ^3.4.3
Requires (Dev)
- phpunit/phpunit: ^9.5
- slim/slim: ^4.11
This package is auto-updated.
Last update: 2024-10-10 19:41:45 UTC
README
TWIG filter to turn hashtags into html links. Provides interfaces to work with a Slim Framework Router, or a base URL.
Installation
- Install through composer.
composer require techwilk/twig-hashtagify
- Then configure base url using one of the interfaces provided, or write your own:
Base Url Interface:
use TechWilk\TwigHashtagify\HashtagifyUrlGenerator\BaseUrlHashtagifyUrlGenerator; use TechWilk\TwigHashtagify\HashtagifyExtension; use TechWilk\TwigHashtagify\HashtagifyRuntimeLoader; $urlGenerator = new BaseUrlHashtagifyUrlGenerator('https://example.com/hashtag/'); $twig->addExtension(new HashtagifyExtension()); $twig->addRuntimeLoader(new HashtagifyRuntimeLoader($urlGenerator));
Slim Router Interface:
Add the following extension as a twig dependency
use TechWilk\TwigHashtagify\HashtagifyExtension; $twig->addExtension(new HashtagifyExtension());
Add the following middleware after your TwigMiddleware
to setup our dependencies
use TechWilk\TwigHashtagify\HashtagifyMiddleware; $app->add(HashtagifyMiddleware::createFromContainer($app, 'route-name', 'argument-name'));
Use
Use as a standard twig filter:
{{ 'this text with #hashtags' | hashtagify }}
Example
Turns this:
This is some text with #hashtags in it
Into this:
This is some text with <a href="http://example.com/hashtag/hashtags">#hashtags</a> in it