New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New feature: template inheritance #2469

merged 1 commit into from Oct 25, 2018


None yet
2 participants

roadster31 commented Jan 30, 2018

This PR introduces a new feature, the template inheritance. You can now create a new template, and redefine only the required files instead of copying the whole template.

To do so, you have to create in your template directory a template descriptor file, named template.xml, which contains some information about your template:

<?xml version="1.0" encoding="UTF-8"?>
<template xmlns=""
    <descriptive locale="fr">
        <title>Ce template back-offcie hérite de "default"</title>
    <descriptive locale="en">
        <title>This back-offcie template inherits from the "default" template</title>
            <name>Thelia team</name>

The schema is very similar to the modules descriptor. The important element here is parent, which identifies the parent template, which should be an existing template of the same type (fo, bo, pdf, mail) as the child template. In our example, the new template inherits from the default template.

All template files are inherited, including the assets, the translations and the module overrides.

However, you can define specific translations for your template, and use them by declaring a default translation domain in your template files, for example {default_translation_domain domain='bo.your_template_name'}, or using the domain (abbreviated d) parameter of the intl Smarty function : {intl l='Edit a customer' d='bo.your_template_name'}

You can also use your own assets, as in a regular template. Use a {declare_assets directory='your_asset_directory'} if your CSS or JS references relative resources, so that they could be copied in the web/assets directory.

Additionally, you can also override the assets of your parent if you're using the same asset directory structure. For example, if you want to override the assets/css/styles.css of your parent, create a assets/css/styles.css in your template, and it will override the parent's one.

⚠️ Don't forget to clear the cache when manipulating templates, as template and/or assets information may be cached by Thelia.

The ParserInterface interface has now 2 new methods :

  • pushTemplateDefinition(TemplateDefinition $templateDefinition, $fallbackToDefaultTemplate) to set a new template definition, while saving the current one
  • popTemplateDefinition() to restore a previously pushed template

These methods are useful to temporary set a template (for sending a mail, for example), and then restore the current front or back template.


This comment has been minimized.


InformatiqueProg commented Jan 30, 2018


@roadster31 roadster31 merged commit a43dfa2 into thelia:master Oct 25, 2018

2 checks passed

Scrutinizer 1 new issues, 44 updated code elements
continuous-integration/travis-ci/pr The Travis CI build passed

@roadster31 roadster31 deleted the roadster31:template-inheritance branch Oct 25, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment