2017 © Pedro Peláez
 

symfony-bundle shortcode-bundle

Bundle that provides a Twig filter to support WordPress-like shortcodes.

image

drinky78/shortcode-bundle

Bundle that provides a Twig filter to support WordPress-like shortcodes.

  • Tuesday, October 28, 2014
  • by drinky78
  • Repository
  • 1 Watchers
  • 0 Stars
  • 4 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 7 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Bundle that provides a Twig filter to support WordPress-like shortcodes., (*1)

Important: It's an early prototype!, (*2)

Currently supported are tags of this form: * [demo] (simple tags) * [demo var=xxx var2=yyy] (tags with unquoted attributes), (*3)

Not yet supported are: * [demo]...[/demo] (tags with embedded content) * [demo var="xxx"] (tags with quoted attributes), (*4)

Installation

Add ShortcodeBundle in your composer.json:, (*5)

{
    "require": {
        "drinky78/shortcode-bundle": "dev-master"
    }
}

Register the bundle in AppKernel, (*6)

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new MW\Bundle\ShortcodeBundle\MWShortcodeBundle(),
    );
}

How to use:

1. Create a new shortcode handler

``` php <?php, (*7)

MyProject\Bundle\TestBundle\Shortcode\DemoShortcode.php

namespace MyProject\Bundle\TestBundle\Shortcode;, (*8)

use MW\Bundle\ShortcodeBundle\Shortcode\BaseShortcode;, (*9)

class DemoShortcode extends BaseShortcode {, (*10)

public function parse($options)
{
    // TODO: Render your content
    return 'Shortcode content';
}

}, (*11)


###2. Define the shortcode as a service (the alias will be the name of your shortcode): ``` xml <service id="myproject.shortcode.demo" class="MyProject\Bundle\TestBundle\Shortcode\DemoShortcode"> <tag name="mw.shortcode" alias="demo" /> </service>

YML example, (*12)

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

html <div>{{ page.content|shortcodes }}</div>, (*13)

The Versions

28/10 2014

dev-master

9999999-dev

Bundle that provides a Twig filter to support WordPress-like shortcodes.

  Sources   Download

MIT

The Requires

 

by Marco Radossi

shortcode