When you start creating theme using layoutBundle, following questions will help you understand “how to create theme with LayoutBundle”.
You can place your all theme in any bundle. The 'themes' directory will be created in bundles 'views' directory. For example, you have a bundle with name of ThemeBundle or FrontBundle, create a 'themes' directory in your ThemeBundle. Here is the directory hierarchy.
ThemeBundle->Resources->views->themes
Your can create many themes in 'themes' directory
After creating themes directory, register your theme bundle in config.yml
kamran_layout:
_theme_bundle: 'YourBundleName' // bundle name with namespaces
One of the easiest improvements we can implement with our pre content is syntax highlighting. It makes code easier to read and understand. In addition, it will make our design a bit more vibrant.
This file is called theme configuration file and is responsible for handling theme layouts.You can define URL rules to themes and theme templates. Themes regions are also defined in this file.
layouts.xml file is theme configuration file which handles all theme related tasks
Creating a theme using LayoutBundle is easy, here are steps to create a theme.
You need to install LayoutBundle using composer
$ composer require kamran/layout-bundle dev-master
This bundle provides the flexibility to choose any bundle for theme placement. Choose wisely, like sometime we use a FrontBundle in project, and put all front page/index page related items in that bundle. So we recommend that bundle for placment of theme.
So I have created the 'themes' directory in my FrontBundle. Here is the directory path.
FrontBundle->Resources->views->themes
After creating themes directory in FrontBundle, you need to register your FrontBundle in config.yml
kamran_layout:
_theme_bundle: 'FrontBundle' // bundle name with namespaces, use your namespace with bundle name
For handling themes you needs to create theme configuration file with the name of "layouts.xml" in "themes" directory.
FrontBundle->Resources->views->themes->layouts.xml
You can create theme with any name. Lets create a theme directory with "bluemoon" name.
FrontBundle->Resources->views->themes->bluemoon
In your theme, you can create parent templates for different type of content which have different layouts.
For example, create a template "front.html.twig". This template will be used for "Front Page"
FrontBundle->Resources->views->themes->bluemoon->front.html.twig
You can create more templates in theme according to your needs
Here is the basic pattern of "layouts.xml" file
Now we have added some theme templates in layouts.xml file
Themes default template: This is the default template for your theme, if you leave this attribute blank then default template will be used.
Add following tag in top of your child templates(controllers action templates)
{% extends themes %}