# easyTemplate360

## Links

[Wiki](https://solution360.atlassian.net/wiki/spaces/ET360V2/overview)  
[Changelog](https://solution360.atlassian.net/wiki/spaces/ET360V2/pages/3415474177/Changelog)

## Template-Functions

Listed here are all easyTemplate360 specific Smarty template functions. Additionally to these functions, easyTemplate360 also supports all NOVA template functions.

### et_renderGrid  

Renders the widgets for a given area/grid according to their configuration.

#### Parameters:

- **id** - The ID of the grid to be rendered.
- fallbackId - The ID of the grid to be rendered if the original ID has no widgets.
- context - Context for rendering if applicable, e.g. for menu grids.

#### Return Value:

- The rendered HTML.

### et_getCompilationTimestamp  

Gets the timestamp of the last CSS compilation by the backend, e.g. when triggered by saving colors or fonts. This can be used for cache busting.

#### Parameters:

- none

#### Return Value:

- The timestamp of the last compilation as string or '0' if none was found.

### et_getDevice

Gets the current device as detected by the MobileDetect library (e.g. via the User Agent). Do not confuse this with breakpoints.

#### Parameters:

- assign - The Smarty variable to which the result should be assigned instead of printing it directly.

#### Return Value:

- The detected device as 'phone', 'tablet' or 'desktop'.

### et_language

Works similar to the lang template function but is used for language variables that are custom for easyTemplate360.  
It also registers undefined variables as unspecified for the shop backend but instead of displaying "#custom.*key*#" it displays a default value provided by easyTemplate360.
If the given variable (custom.<key>) is assigned a value in the shop backend, that value will be displayed.

#### Parameters:

- **key** - The unique key of the language variable.

#### Return Value:

- The shop backend language variable for custom.*key* or the easyTemplate360 default value for that language variable if it was not set in the shop backend.

### et_getSetting

Loads a specific setting from the easyTemplate360 backend. These are settings that do not belong to widgets, i.e. "global" settings like area settings and the likes.

#### Parameters:

- **section** - The ID of the setting group to load.
- key - The key of the setting in the given setting group. If key is omitted, the whole setting group is returned.
- assign - The Smarty variable to which the result should be assigned instead of printing it directly.

#### Return Value:

- The setting value as string if a key was given or all settings of a setting group as associative array if no key was given.

### et_getButtonSettings

Gets the settings for a given button type from the backend.

#### Parameters:

- **type** - The type for which the settings should be loaded.
- assign - The Smarty variable to which the result should be assigned instead of printing it directly.

#### Return Value:

- The configuration for the specified button type as associative array.

### et_getGlobalSettings

Gets the settings for the setting group "Global".

#### Parameters:

- assign - The Smarty variable to which the result should be assigned instead of printing it directly.

#### Return Value:

- An associative array of the *resolved* global area settings.

### et_getMenuSettings

Gets the settings for the setting group "Menu", i.e. the global settings for menus.

#### Parameters:

- assign - The Smarty variable to which the result should be assigned instead of printing it directly.

#### Return Value:

- An associative array of the *resolved* menu area settings.

### et_getFontSettings

Gets the settings for the setting group "Fonts", i.e. the global settings for fonts.

#### Parameters:

- assign - The Smarty variable to which the result should be assigned instead of printing it directly.

#### Return Value:

- An associative array of the *resolved* font setting group settings.

### et_getFonts

Gets an array of the currently active fonts as set in the setting group for fonts in the plugin backend.

#### Parameters:

- assign - The Smarty variable to which the result should be assigned instead of printing it directly.

#### Return Value:

- An array of the currently active fonts (which are themselves associative arrays with further detail information).

### et_getIcon

Gets the icon (i.e. CSS classes) for the given icon key.

#### Parameters:

- **key** - The key for the icon to load (e.g. 'shipping', 'download', 'edit')
- assign - The Smarty variable to which the result should be assigned instead of printing it directly.

#### Return Value:

- The CSS classes as string for the given icon key.

### et_isPreviewMode

Checks if the template is currently viewed in admin preview. This is for the easyTemplate360 preview mode, not the preview mode from JTL-Shop (5.2.0+) itself.

#### Parameters:

- assign - The Smarty variable to which the result should be assigned instead of printing it directly.

#### Return Value:

- Boolean true/false depending on if the template is view in preview mode-

### et_getFavicon

Gets the favicon image from the global setting group.

#### Parameters:

- assign - The Smarty variable to which the result should be assigned instead of printing it directly.

#### Return Value:

- The image data as associative array. Note that the info itself might contain empty fields if nothing was configured in the backend.

### et_getPluginBaseUrl

Gets the base URL to the plugin backend. This is used internally to create the links for the pencil mode.

#### Parameters:

- none

#### Return Value:

- The base URL to the plugin backend or an empty string if the plugin was not found.

### et_shouldShowAlertList

Helper function used before rendering the alert list. Some alerts in JTL may define that they should not be displayed in the default alert list.  
This function is used to prevent rendering an empty alert list if none of the contained alerts should be displayed.

#### Parameters:

- **alertList** - The list of alerts to check.
- assign - The Smarty variable to which the result should be assigned instead of printing it directly.

#### Return Value:

- Boolean true/false depending on if the alert list contains at least one alert that should be displayed in it.

### et_getShopVersion

Returns the current shop version as defined by \APPLICATION_VERSION. *Not used by easyTemplate360 parent.*

#### Parameters:

- assign - The Smarty variable to which the result should be assigned instead of printing it directly.

#### Return Value:

- A string with the current \APPLICATION_VERSION.

### et_isShopVersionAtLeast

Checks if the current shop version is at least the given version.  
This function is used mainly to provide backwards compatibility for older shop versions running newer easyTemplate360 versions.

#### Parameters:

- **value** - The version string to check against, e.g. '5.1.0'
- assign - The Smarty variable to which the result should be assigned instead of printing it directly.

#### Return Value:

- Boolean true/false depending on if the current shop version as defined by \APPLICATION_VERSION is at least the given version or higher.

### et_isPencilModeEnabled

Checks if the pencil mode for admins is enabled.  
In the plugin backend you can disable the pencil mode via a button.  
This is the corresponding check in the template.

#### Parameters:

- assign - The Smarty variable to which the result should be assigned instead of printing it directly.

#### Return Value:

- Boolean true/false depending on if the pencil mode is active or not.

### et_getBreakpoints

Returns the configured breakpoints as defined by the defaults.json of the current template.

#### Parameters:

- assign - The Smarty variable to which the result should be assigned instead of printing it directly.

#### Return Value:

- An associative array with keys  xsMax, smMin, smMax, ..., xlMin and floating point values (in pixels).

### et_getReviewCount

Gets the total number of reviews/ratings for a given product. 
This is a helper function necessary to provide this information in contexts where products are only loaded with default options (i.e. with reduced information).

#### Parameters:

- **article** - The Artikel class instance to get the reviews for.
- assign - The Smarty variable to which the result should be assigned instead of printing it directly.

#### Return Value:

- The total amount (as string) of reviews/ratings for the given product.

### et_hasConsent

Checks if the given consent object key has consent given or not via the JTL Shop's own consent manager.

#### Parameters:

- **key** - The consent key (e.g. 'youtube') to check.
- assign - The Smarty variable to which the result should be assigned instead of printing it directly.

#### Return Value:

- Boolean true/false depending on if the given key has consent.

### et_isUselessFilter

Determines if a given filter is useless.

A filter is considered useless if:

1. it is an instance of AbstractFilter,
2. it is not active currently and
3. all its options do not decrease the current result set of products.

#### Parameters:

- **filter** - an instance of AbstractFilter
- **resultCount** - the current result count or count to check against
- assign - The Smarty variable to which the result should be assigned instead of printing it directly.

#### Return Value:

- Boolean true/false depending on if the filter can be considered useless.

### et_getGlobalVariable

Fallback function that can be used when the Smarty variable $et_global is not available (particularly useful in AJAX / IO call context!)

#### Parameters:

- **assign** - The Smarty variable to which the result should be assigned. Note that this function does not print anything, ever.

#### Return Value:

- The value of what should be contained in $et_global.

### et_getImageSize

Gets size information (image dimensions!) for the given image by reading it from the file system.

#### Parameters:

- **src** - The path to the image, relative to the shop root or optionally the URL to the image (but it must still be below the shop root to work).
- assign - The Smarty variable to which the result should be assigned instead of printing it directly.

#### Return Value:

- Returns an associative array with 'width' and 'height' as integer pixel values and 'attributes' with an attribute string to be used on an `<img>` tag (i.e. `width="123" height="456"`). 'width' and 'height' are 0 and the 'attributes' string is empty if the dimensions could not be determined.

## Custom Widgets

Custom Widgets must be created in child templates only.  
They consist of three components: a backend definition, a PHP class and a template file.

### Backend Definition

The definition of how the custom widget should appear in the plugin backend and which settings it provides.

*see config/custom_widgets/README.md*

### PHP Class

The file that resolves the configured settings and prepares the Smarty variable for the template of the custom widget.

*see src/CustomWidgets/README.md*

### Template File

The template file that will be rendered for the custom widget.

*see custom_widgets/README.md*