Developed with love by KnpLabs Hire us for your project!
16

ThemeBundle

by SymEdit

[READ-ONLY] Themes for Symfony2

SymEdit Theme Bundle

symedit_theme:
    theme_directory: %kernel.root_dir%/../themes
    public_directory: themes
    active_theme: default
    templates:
        bundles: [AcmeDemoBundle]

The theme bundle will load templates from the `{theme_directory}/{active_theme}/templates
folder. It also will allow you to use local assetic files. Themes are comprised
of a simple YAML definition (in theme.yml):

name: default
parent: base
title: Default Theme
description: Default Theme for all websites
stylesheets:
    filters: [cssrewrite]
    inputs:
       - 'bundles/acmedemo/bootstrap/css/bootstrap.min.css'
       - 'bundles/acmedemo/css/font-awesome.min.css'
       - '@AcmeDemoBundle/Resources/less/site.less'
       - 'css/site.less' # Taken from /{active_theme}/css/site.less
javascripts:
    # Same as stylesheets
    inputs: []

You will now use your css in your templates like so:

{% stylesheets '@theme_css' %}
<link rel="stylesheet" href="{{ asset_url }}">
{% endstylesheets %}

You can always include other stylesheets there as well, the @theme_css is mostly
to be able to access local assets inside your theme. Any bundle assets from
other bundles can be intermixed:

{% stylesheets
    '@theme_css'
    '@AcmeDemoBundle/Resources/less/site.less' %}
<link rel="stylesheet" href="{{ asset_url }}">
{% endstylesheets %}

This same applies for javascripts as well and you can get it through assetic
by @theme_js.

Parent Themes

You can set your theme to have a parent (should be the slug of the theme, and
themes are located in %theme_dir%/{theme_name}/theme.yml). If your theme has a
parent, then those templates are second in line to be used. After that are the
overrides. If you use an override like "Framework" then templates being
referenced like: @Framework/template.html.twig will instead use your theme
directories to find a template. Likewise, if you use @Theme/template.html and
it only existed in the @Framework namespace, it would still work.

When using a parent theme, you can also store your assets in any theme you'd
like, or have them split up. It will start with your current theme and move
up through all parents trying to locate the resource, so assets in your current
theme take precedence. This helps if you have lots of similar themes so you can
store shared assets in a "base" theme.

Templates

All your template includes and extends should use the @Theme namespace:

{% extends '@Theme/Page/base.html.twig' %}

{% block content %}
    {% include '@Theme/Includes/content.html.twig' %}
{% endblock %}

Forms

You can select a template using the template form type:

$builder->add('page_template', 'template');
symedit_theme:
theme_directory: ~ # Required
public_directory: themes
active_theme: default
namespace_overrides: []
templates:
bundles: []
  • Update composers to use psr-4 and add composer.json to missing bundles
    By isometriks, 2 years ago
  • Wrong method used, was overwriting previous prefixes
    By isometriks, 3 years ago
  • Rename twig resource class
    By isometriks, 3 years ago
  • Simplify
    By isometriks, 3 years ago
  • Add check for external paths in theme stylesheets/javascripts
    By isometriks, 3 years ago
  • Fix getDirectory to getThemeDirectory
    By isometriks, 3 years ago
  • Fix template directory inheritance. Need to reverse because of how prepend works.
    By isometriks, 3 years ago
  • Stylizer Theme Loader for styles should also include parent styles as well. Child styles should overwrite just like they do normally.
    By isometriks, 3 years ago
  • CSFixer + Headers
    By isometriks, 3 years ago
  • Clean up namespace
    By isometriks, 3 years ago
  • Speed up theme factory by setting the debug on configcache
    By isometriks, 3 years ago
  • Fix theme yaml in docs
    By isometriks, 3 years ago
  • Fix how themes are loaded as it wasn't working correctly with multiple parents. Add symedit:theme:unique which checks to see if any of your templates are duplicated.
    By isometriks, 3 years ago
  • Allow themes to be serialized
    By isometriks, 3 years ago
  • Readme update and more comments
    By isometriks, 3 years ago
  • Remove the subscriber and make a new Loader instead to setup the paths
    By isometriks, 3 years ago
  • When finding resources for assetic recurse through any parent themes to try to find the resource so it can be overwritten
    By isometriks, 3 years ago
  • Allow themes to have a chain of parents so they can be extended.
    By isometriks, 3 years ago
  • More UI fixes, simplified some admin templates, made things more consistent. Added icons to most all action buttons
    By isometriks, 3 years ago
  • Don't load directory if it doesn't exist
    By isometriks, 3 years ago
  • Require theme_directory
    By isometriks, 3 years ago
  • Squashed commit of the following:
    By isometriks, 3 years ago
  • CS Fixer and Headers
    By isometriks, 3 years ago
  • If stylizer exists then set the storage method to a yaml based theme storage. So you save your styles to your theme instead of to the app directory. Making it easier to bundle themes up and re-use.
    By isometriks, 3 years ago
  • Added a command that lets you copy a template from anywhere in the theme heirarchy to your local theme folder easily.
    By isometriks, 3 years ago
  • Fix namespace overrides to allow Theme to access of their paths as well not just make the theme templates the first in their namespace.
    By isometriks, 3 years ago
  • Use the interface instead
    By isometriks, 3 years ago
  • Prepend twig form resource
    By isometriks, 3 years ago
  • Cache the theme config for faster reloading
    By isometriks, 3 years ago
  • CS Fixer
    By isometriks, 3 years ago