About extensions
How to share code between websites?
Extensions are "plugins" that you can add to a website
They allow you to share code across websites and themes. When the code is updated, the latest version is on all websites that have installed the extension.
Extensions can be very simple or have a lot of blocks and flexibility, depending on what you want to build.
Just like themes, extensions are made of:
variables, locales, blocks, list, pages, head... (HTML)
like theme, they can access unit data
assets such as Javascript, CSS, images
For example, you could have extensions for:
an event-tracking code, that should be updated on all websites (only need a Javascript file)
a generic cookie bar (HTML / CSS / JS)
a guest portal with login, signup, editing profiles, etc... (page templates, blocks available in composer, configuration blocks, etc..)
Can themes and extensions communicate?
Themes and extensions are "separate bubbles". They live separately and have their own set of blocks, design settings, locales, etc...
By design, from a theme, you cannot call a variable from an extension, a locale, a design setting, or a block... And vice-versa, theme and extensions are entirely separated. Indeed, extensions are linked to a website. They are not aware of "which theme" is the website using. And in the same way, the extension is not aware of which extensions are installed on the website.
You can do communication using events in Javascript by defining predefined events, but this will not be using Galaxy features.
The only way to have code from the extension write inside the theme (for example, put something at a very specific place in the header, is to use the zone concept)
"Zone": Injecting HTML inside a themeAre extensions using a different syntax?
Extensions use the same syntax and the same directory structure as themes.
Everything that works on a theme also works on an extension 🎉
The update process is also the same as for a theme.
When do you need extensions?
Here are some examples where an extension can be useful:
a feature that needs to be maintained by a different team than the one maintaining the website theme
Each extension and each theme have their own code repository. This means that for example, Team A could maintain a theme and Team B could maintain just the extension providing a specific feature.
a feature shared in different themes, that you want to update in one place, without having to update several themes
For example, a Currency Switcher that gets data from an API. The logic to get the currencies, store it in browser storage, the design would be the same on all websites. When updating it, it would go on all local websites.
Last updated