ru en

Symfony Widgets Bundle

Widgets Bundle - a bundle for easy widgets management. (Supports only widgets which require only client-side code for displaying). Includes both client side (for displaying) and admin side (adds admin classes and has a SonataAdminBundle dependency) functionality.

Can be used (for example) for adding counters, banners, advertising network codes (google adsense, etc).

Was created during this blog has been developing.

1. Installation

1) Install  the bundle via Composer:

$ composer.phar require harentius/widgets-bundle

2) Enable the bundle in the kernel:

// app/AppKernel.php

public function registerBundles()
    $bundles = array(
        // ...
        new Harentius\WidgetsBundle\HarentiusWidgetsBundle(),

    // ...

3) Include configuration:

    - { resource: "@HarentiusWidgetsBundle/Resources/config/config.yml" }

(It is for enabling FIND_IN_SET function in mysql (this, unfortunality limits usage of this bundle with other DBs))

4) Configure the bundle:

    # List of routes, where widgets can be placed
            # User-friendly name for displaying in admin section (sonata)
            name: Homepage
            name: Article
            # Parameters, present in route
                    # Source (Now only entity supported)
                        class: HarentiusBlogBundle:Article
                        # Value to be passed to the route 
                        field: slug
                        # Value to be shown in admin section
                        identity: title
    # Registering widgets: key used in templates (look behind), value - shown in admin section
        widgets_block_sidebar: Sidebar
        widgets_block_bottom_left: Bottom left
        widgets_block_bottom_right: Bottom right

5) Place in templates where you want:

    {{ harentius_widget('widgets_block_sidebar') }}
    {{ harentius_widget('widgets_block_bottom_left') }}
    {{ harentius_widget('widgets_block_bottom_right') }}

The bundle is ready for using. Some explanations:

Key routes  sets a list of routes where widgets can be displayed. Key is a name of route (same as in routing.yml), value name - is a label that will be shown in the admin section. If route has parameters, you has to configure it using key parameters. Key is a name of a parameter,

source - can configure only an entity source at the moment (I plan support repositories/queries in future)

field - value of this field will be passed to the route

identity - a human-readable entity representation (used for displaying in the admin section).

For example, field - it is a slug, identity - a title of the article.

Further the list of available widgets (key widgets)

Key - arbitrary widget id that should be passed to a function, called inside template, value - human-readable representation for displaying inside the admin section.

Call in templates:

    {{ harentius_widget('widgets_block_bottom_right') }}

(The function argument is a configured block).

A Critique/Issues/Wishes/Pull requests/Bug reports encouraged.