PHPackages                             jagilpe/ajax-blocks-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. jagilpe/ajax-blocks-bundle

ActiveSymfony-bundle[API Development](/categories/api)

jagilpe/ajax-blocks-bundle
==========================

Symfony Bundle for rendering blocks refreshable with ajax requests

1.0.0(9y ago)3764MITPHPPHP &gt;=5.6.0

Since May 4Pushed 9y agoCompare

[ Source](https://github.com/jagilpe/ajax-blocks-bundle)[ Packagist](https://packagist.org/packages/jagilpe/ajax-blocks-bundle)[ Docs](https://github.com/jagilpe/ajax-blocks-bundle)[ RSS](/packages/jagilpe-ajax-blocks-bundle/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (21)Versions (2)Used By (0)

AjaxBlocksBundle
================

[](#ajaxblocksbundle)

AjaxBlocksBundles is a Symfony bundle that provides an easy way to render in a Twig template blocks that can be updated using ajax requests.

[![Build Status](https://camo.githubusercontent.com/aac45ca7339dfec4591a7fae906f193b9e938d31c9a4a0bc1f489ca007759bbe/68747470733a2f2f7472617669732d63692e6f72672f6a6167696c70652f616a61782d626c6f636b732d62756e646c652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/jagilpe/ajax-blocks-bundle)[![codecov](https://camo.githubusercontent.com/a9d5053e9c9f285e2a0aa43ab1fa2cabb7decf01b01b6e0007df3fc34be39057/68747470733a2f2f636f6465636f762e696f2f67682f6a6167696c70652f616a61782d626c6f636b732d62756e646c652f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/jagilpe/ajax-blocks-bundle)[![Latest Stable Version](https://camo.githubusercontent.com/14e04601b4e19bce5bfa4c1c9c592677088ca25d98de6230a5955260b2b3e54c/68747470733a2f2f706f7365722e707567782e6f72672f6a6167696c70652f616a61782d626c6f636b732d62756e646c652f762f737461626c65)](https://packagist.org/packages/jagilpe/ajax-blocks-bundle)[![License](https://camo.githubusercontent.com/f1a1ba7d5ca003294a99061073377689fe1f297348c3f2b58ce77fa8f1e2ff75/68747470733a2f2f706f7365722e707567782e6f72672f6a6167696c70652f616a61782d626c6f636b732d62756e646c652f6c6963656e7365)](https://packagist.org/packages/jagilpe/ajax-blocks-bundle)

Installation
============

[](#installation)

You can install the bundle using composer:

```
composer require jagilpe/ajax-blocks-bundle
```

or add the package to your composer.json file directly.

To enable the bundle, you just have to register the bundle in your AppKernel.php file:

```
// in AppKernel::registerBundles()
$bundles = array(
    // ...
    new Jagilpe\AjaxBlocksBundle\AjaxBlocksBundle(),
    // ...
);
```

Then you have to add the route required for reloading the blocks. In app/config/routing.yml

```
jgp_ajax_blocks:
    resource: "@AjaxBlocksBundle/Resources/config/routing.xml"
    prefix: "/jgp-ajax-blocks"
```

Finally you have to include the provided javascript file somewhere in your base template. If you use assetic to manage the assets:

```
{% block javascripts %}
    {{ parent() }}
    {% javascripts
        'bundles/ajaxblocks/js/ajax-blocks.js' %}

    {% endjavascripts %}
{% endblock %}
```

This javascript depends on jQuery, so you have to load it somewhere in the template before this file.

Usage
=====

[](#usage)

Basic usage
-----------

[](#basic-usage)

### Creating an ajax block

[](#creating-an-ajax-block)

You can write a block to be rendered as an ajax block exactly as you would write if you would embed it in a template rendering directly the output of a controller.

Write a controller that builds and returns the desired block as usual:

```
class DefaultController extends Controller
{
    // ...
    public function myAjaxBlockAction()
    {
        $variables = array();

        // Get the required variables for the template as one would usually do
        // ...

        return $this->render('::my_ajax_block.html.twig', $variables);
    }
}
```

There is no need to define a route for this controller.

### Embed the block in the page

[](#embed-the-block-in-the-page)

To include the block in the page simply insert it the template using the `jgp_ajax_block` twig function, passing the controller as the first parameter.

```
{{ jgp_ajax_block('AppBundle:Default:myAjaxBlock') }}
```

### Reloading the block

[](#reloading-the-block)

The main goal of this bundle is to easily divide the page in blocks that can be independently refreshed without having to reload all the page. The logic that triggers this block reload is part of the logic of the application and should be implemented in javascript as part of the application's frontend.

We can access the ajax block through the selector `[data-target="jgp-ajax-block"]` and reload its content invoking the reloadBlock action of the jgpAjaxBlock jQuery plugin.

The following code would reload the content of all the ajax blocks present in the page:

```
$('[data-target="jgp-ajax-block"]').jgpAjaxBlock('reloadBlock');
```

If we only want to reload one determined block, we should wrap it with another element and select it through it:

```
$('#a-determined-block [data-target="jgp-ajax-block"]').jgpAjaxBlock('reloadBlock');
```

Advanced usage
--------------

[](#advanced-usage)

### Passing parameters to the block

[](#passing-parameters-to-the-block)

You can pass parameters to the block exactly the same way you would do it with another controller, but with one important restriction: they must be strings. This is because the block is reloaded using an ajax call, and therefore this parameters must be encoded in the url of this call. If for example you wanted to pass an entity to the controller, you should pass the id of the entity and then load it in the controller's code.

The parameters should be passed as an array in the second parameter of the `jgp_ajax_block` function in the template.

```
class DefaultController extends Controller
{
    // ...
    public function myAjaxBlockAction($entityId, $otherParameter)
    {
        $variables = array();

        // Get the required variables for the template as one would usually do
        // ...

        return $this->render('::my_ajax_block.html.twig', $variables);
    }
}
```

```
{{ jgp_ajax_block('AppBundle:Default:myAjaxBlock', { entityId: 1, otherParameter: 'my value' }) }}
```

### Passing options to the jQuery plugin

[](#passing-options-to-the-jquery-plugin)

By default the jQuery plugin is automatically loaded with the page load. To be able to customize the load of the plugin we have to disable the auto load of the plugin. This can be done by passing the option `autoload` as `false` in the third parameter of the `jgp_ajax_block` twig function.

```
{{ jgp_ajax_block('AppBundle:Default:myAjaxBlock', { }, { autoload: false }) }}
```

After that you should load the plugin in the javascript code of your frontend with the custom options you want.

```
$('[data-target="jgp-ajax-block"]').jgpAjaxBlock({
  'onReload': function(block) {
    // Do something with the loaded block
  }
});
```

#### Adding a reload callback to the block

[](#adding-a-reload-callback-to-the-block)

You can pass a reload callback to the jQuery plugin that controls the block by passing it as an option. This callback receives the reloaded block as parameter. For this to work the autoload option of the block must be disabled.

```
$('[data-target="jgp-ajax-block"]').jgpAjaxBlock({
  'onReload': function(block) {
    // Do something with the loaded block
  }
});
```

API Reference
=============

[](#api-reference)

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

3344d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/25b6f0bda16c24e432de8c8e9b71f38c9f697054ef71f1cb6986756de7bbee5b?d=identicon)[jagilpe](/maintainers/jagilpe)

---

Top Contributors

[![javier-gilpereda](https://avatars.githubusercontent.com/u/79689747?v=4)](https://github.com/javier-gilpereda "javier-gilpereda (5 commits)")

---

Tags

symfonyajaxblock

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/jagilpe-ajax-blocks-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/jagilpe-ajax-blocks-bundle/health.svg)](https://phpackages.com/packages/jagilpe-ajax-blocks-bundle)
```

###  Alternatives

[easycorp/easyadmin-bundle

Admin generator for Symfony applications

4.3k17.5M378](/packages/easycorp-easyadmin-bundle)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.4M196](/packages/sulu-sulu)[pimcore/pimcore

Content &amp; Product Management Framework (CMS/PIM/E-Commerce)

3.8k3.8M464](/packages/pimcore-pimcore)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

585.4M524](/packages/shopware-core)[chameleon-system/chameleon-base

The Chameleon System core.

1027.9k4](/packages/chameleon-system-chameleon-base)[open-dxp/opendxp

Content &amp; Product Management Framework (CMS/PIM)

9317.2k55](/packages/open-dxp-opendxp)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
