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
merged 1 commit into from Oct 25, 2018

Conversation

Projects
None yet
2 participants
@roadster31
Contributor

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="http://thelia.net/schema/dic/template"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://thelia.net/schema/dic/template http://thelia.net/schema/dic/template/template-1_0.xsd">
    <descriptive locale="fr">
        <title>Ce template back-offcie hérite de "default"</title>
    </descriptive>
    <descriptive locale="en">
        <title>This back-offcie template inherits from the "default" template</title>
    </descriptive>
    <parent>default</parent>
    <languages>
        <language>en_US</language>
        <language>fr_FR</language>
    </languages>
    <version>1.0.0</version>
    <authors>
        <author>
            <name>Thelia team</name>
            <company>thelia.net</company>
            <email>contact@thelia.net</email>
            <website>thelia.net</website>
        </author>
    </authors>
    <thelia>2.4.0</thelia>
    <stability>prod</stability>
</template>

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.

@InformatiqueProg

This comment has been minimized.

Contributor

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
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

@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