drinky78 / shortcode-bundle
Bundle that provides a Twig filter to support WordPress-like shortcodes.
Installs: 10
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 6
Type:symfony-bundle
Requires
- php: >=5.3.3
- symfony/framework-bundle: >=2.2
This package is not auto-updated.
Last update: 2024-12-31 10:08:07 UTC
README
Bundle that provides a Twig filter to support WordPress-like shortcodes.
Important: It's an early prototype!
Currently supported are tags of this form:
[demo]
(simple tags)[demo var=xxx var2=yyy]
(tags with unquoted attributes)
Not yet supported are:
[demo]...[/demo]
(tags with embedded content)[demo var="xxx"]
(tags with quoted attributes)
###Installation
Add ShortcodeBundle in your composer.json:
{
"require": {
"drinky78/shortcode-bundle": "dev-master"
}
}
Register the bundle in AppKernel
<?php
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
// ...
new MW\Bundle\ShortcodeBundle\MWShortcodeBundle(),
);
}
##How to use:
###1. Create a new shortcode handler
<?php #MyProject\Bundle\TestBundle\Shortcode\DemoShortcode.php namespace MyProject\Bundle\TestBundle\Shortcode; use MW\Bundle\ShortcodeBundle\Shortcode\BaseShortcode; class DemoShortcode extends BaseShortcode { public function parse($options) { // TODO: Render your content return 'Shortcode content'; } }
###2. Define the shortcode as a service (the alias will be the name of your shortcode):
<service id="myproject.shortcode.demo" class="MyProject\Bundle\TestBundle\Shortcode\DemoShortcode"> <tag name="mw.shortcode" alias="demo" /> </service>
YML example
parameters:
myproject.shortcode.demo: MyProject\Bundle\TestBundle\Shortcode\DemoShortcode
services:
myproject.shortcode.demo:
class: %myproject.shortcode.demo%
tags:
- { name: mw.shortcode, alias: demo }
###3. Use it in your Twig templates
<div>{{ page.content|shortcodes }}</div>