PHPackages                             kamran/layout-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. [Framework](/categories/framework)
4. /
5. kamran/layout-bundle

ActiveSymfony-bundle[Framework](/categories/framework)

kamran/layout-bundle
====================

Handle complex layouts in symfony

1152PHP

Since Oct 12Pushed 10y ago1 watchersCompare

[ Source](https://github.com/kamranshahzad/LayoutBundle)[ Packagist](https://packagist.org/packages/kamran/layout-bundle)[ RSS](/packages/kamran-layout-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

LayoutBundle
============

[](#layoutbundle)

Description:
------------

[](#description)

LayoutBundle help users build layout with pace and provide support for fully customized multi-themes. This bundle provide regions(header, footer, sidebar) and blocks to build compact layout. this bundle provide all components necesssary for layout building e.g : Regions (Header, Footer, Sidebar) and Blocks

Features.
---------

[](#features)

LayoutBundle Provides the following features:

1. Regions and blocks
2. Xml based layout config file
3. Multi-theme
4. Inline blocks
5. Fully customizable

Todo list.
----------

[](#todo-list)

1. Theme assets management
2. Fully customizable header and footer
3. Role/permission base layout
4. Dashboard/Widgets
5. Dynamic Page titles
6. Meta tags, Meta keywords, Meta Description
7. Social Media sharing tags
8. Quick Guide (commands list)

[![alt text](https://github.com/kamranshahzad/kamranshahzad.github.io/raw/master/blog/images/layoutbundle-skeleton.jpg "Layout screenshot")](https://github.com/kamranshahzad/kamranshahzad.github.io/blob/master/blog/images/layoutbundle-skeleton.jpg)

Installation.
-------------

[](#installation)

Using composer

```
$ composer require kamran/layout-bundle dev-master
```

Add the KamranLayoutBundle to your AppKernel.php file:

```
new Kamran\LayoutBundle\KamranLayoutBundle();

```

Configurations.
---------------

[](#configurations)

1. Add the `kamran_layout` service in symfony config:

    ```
     # application/config/config.yml
     	kamran_layout:
     		_theme_bundle: 'AppFrontBundle'
     		_theme_namespaces: ['App','Systems']

    ```

    - `_theme_bundle` : Your theme bundle with namespace.
    - `_theme_namespaces` : Add bundles namespaces for collect blocks for theme regions
2. The themes directories will placed in AppFrontBundle. Here is directory tree. Now create a themes directory in anyone of your bundle as specified below

    - `themes` All themes will be placed inside this directory

```
	[YourBundleName]->Resources->views->themes

```

Themes Configuration file
-------------------------

[](#themes-configuration-file)

For handling themes you need to create a theme configuration file with name of 'layouts.xml' inside `themes` directory:

```
    [YourBundleName]->Resources->views->themes->layouts.xml

```

In `layouts.xml` file you can define your theme rules. Here is the structure of `layouts.xml` file:

```

```

1. `` : This is main tag of layouts.xml file. All theme tags be will wrapped in this tag. so we can have multiple themes in this layout configuration file
2. `` : Every theme will be wrapped inside its own theme tag

    ```
        [YourBundleName]->Resources->views->themes->bluestar

    ```
3. `` : Inside every theme there is a layout tag. This tag has two attributes.

    - `url`: This attribute defines the prefix of url like '/', this means all root level urls will go inside this tag.
    - `template`: This is the default template for your theme, if you leave this attribute blank then default template will be used.
4. `` : templates tag contains all url rules tag.

    - `` : This tag will be a unique, it will have two attributes:
        - `url` : This url can be prefix or page url
        - `template` : The defined template name will be used. If left blank it will inherit template from parent tag

#### Nested Urls in layouts.xml

[](#nested-urls-in-layoutsxml)

Here are example layouts.xml file for nested urls

```

```

#### Use multiple themes

[](#use-multiple-themes)

If you want to implement more then one theme follow the syntax below.

```
    [YourBundleName]->Resources->views->themes->bluestar_frontend
    [YourBundleName]->Resources->views->themes->bluestar_backend

```

```

```

Themes Templates
----------------

[](#themes-templates)

In your themes you must define parent template using url rules. This parent template is defined in `layouts.xml` file. Here is a simple theme parent template:

```
    [YourBundleName]->Resources->views->themes->bluestar->default.html.twig

```

```

    Themes default page

    {% block body %}{% endblock %}

```

Theme parent template is ready, now you need to implement this template with your project. Now add this line in your child template :

```
{% extends themes %}

{% block body %}
    .... child content
{% endblock %}
```

Template Regions &amp; Blocks
-----------------------------

[](#template-regions--blocks)

A theme templates may have many regions(Header, Footer, Sidebar) and inline blocks. Region is collection of blocks. All regions that are to be used in theme are defined in `layouts.xml` file.

#### Define regions in layouts.xml

[](#define-regions-in-layoutsxml)

```

```

`` : All regions are defined in this tag. \* `` : Define regions

#### Use regions in template file

[](#use-regions-in-template-file)

```

    Theme template

    {{ region('header') }}

    {{ region('sidebar') }}

    {% block body %}{% endblock %}

```

#### Add blocks in regions

[](#add-blocks-in-regions)

A region consists of many blocks. You can define any number of blocks in 'layout.xml'

1. A sub configuration file is created for every bundle that is included in the layout sub configuration file. Here is the pattern for creating sub configuration file

    - `[bundlename]_layout.xml` : The file name starts with bundlename as prefix. Use lowercase letter for file name.

    ```
        [FrontBundle]->Resources->views->config->[frontbundle]_layout.xml

    ```
2. Here is the structure of '\[frontbundle\]\_layout.xml' file.

```

```

3. Create blog template file: All block template are placed in blocks directory.

    ```
        [FrontBundle]->Resources->views->blocks->logo.html.twig
        [FrontBundle]->Resources->views->blocks->topmenu.html.twig
        [FrontBundle]->Resources->views->blocks->sidemenu.html.twig

    ```

    block template example:

    ```

            .... block content

    ```

Use inline block in template file
---------------------------------

[](#use-inline-block-in-template-file)

If you want to insert a block direct in theme template file, then you can use inline block option.

1. Regiter a inline block in '\[frontbundle\]\_layout.xml' file.

```

```

```
`` : All regions are defined in this tag.
    * `` : Define your bundle inline blocks for theme.

```

2. Use inline block in theme template.

```

    Theme template

    {{ inlineblock('loginform') }}

    {% block body %}{% endblock %}

```

Passing data to block templates
-------------------------------

[](#passing-data-to-block-templates)

1. If you want to pass some data to your block, then you need to pass a static function which returns the data.

```
class FrontHelper{
    public static function getMenuOption(){
        return array(
            'menu'=>array(
                'home'=> array(
                    'label'=>'Home',
                    'link'=> 'front_index',
                ),
                'user'=> array(
                    'label'=>'Users',
                    'link'=> 'user_index',
                ),
                'organization' => array(
                    'label' => 'Organization',
                    'link' => 'organizations_index',
                ),
            )
        );
    }
}
```

2. Add data class into your block configuration file. ```
        [FrontBundle]->Resources->views->config->[frontbundle]_layout.xml

    ```

```

                \Namespace\FrontBundle\Helper\FrontHelper::getMenuOption

```

3. Block template `topmenu.html.twig`

```

{% for k,v in menu %}

                {{ v.label }}

{% endfor %}

```

Usefull links:
--------------

[](#usefull-links)

1. [Concept behind LayoutBundle](http://kamranshahzad.github.io/blog/the-concept-behind-layoutbundle.html)
2. [Create a simple theme using layoutbundle](http://kamranshahzad.github.io/blog/create-a-simple-theme-using-layoutbundle.html)

Reporting an issue or feature request.
--------------------------------------

[](#reporting-an-issue-or-feature-request)

Issues and feature requests are tracked in the [Github issue tracker](https://github.com/kamranshahzad/LayoutBundle/issues).

How to contribute?
------------------

[](#how-to-contribute)

The contribution for this bundle for public is open, anybody could help me to participate bugs, documentation and code.

License.
--------

[](#license)

This software is licensed under the MIT license. See the complete license file in the bundle:

```
Resources/meta/LICENSE

```

[Read the License](https://github.com/kamranshahzad/LayoutBundle/blob/master/Resources/meta/LICENSE)

###  Health Score

21

—

LowBetter than 18% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity41

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/fbd5ec5cc5c2f7854f39e069772bba84cafefbdf511536cddb99e440b2e5b17c?d=identicon)[kamranshahzad](/maintainers/kamranshahzad)

---

Top Contributors

[![kamranshahzad](https://avatars.githubusercontent.com/u/773620?v=4)](https://github.com/kamranshahzad "kamranshahzad (19 commits)")

### Embed Badge

![Health badge](/badges/kamran-layout-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/kamran-layout-bundle/health.svg)](https://phpackages.com/packages/kamran-layout-bundle)
```

###  Alternatives

[laravel/passport

Laravel Passport provides OAuth2 server support to Laravel.

3.4k85.0M532](/packages/laravel-passport)[nolimits4web/swiper

Most modern mobile touch slider and framework with hardware accelerated transitions

41.8k177.2k1](/packages/nolimits4web-swiper)[laravel/dusk

Laravel Dusk provides simple end-to-end testing and browser automation.

1.9k36.7M259](/packages/laravel-dusk)[laravel/prompts

Add beautiful and user-friendly forms to your command-line applications.

712181.8M596](/packages/laravel-prompts)[cakephp/chronos

A simple API extension for DateTime.

1.4k47.7M121](/packages/cakephp-chronos)[laravel/pail

Easily delve into your Laravel application's log files directly from the command line.

91545.3M590](/packages/laravel-pail)

PHPackages © 2026

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