-
Notifications
You must be signed in to change notification settings - Fork 4
Template Files
- implement a single reusable UI element
- contain only UI-related code
- may only use vanilla PHP and allowed view helpers listed on this page
- may be made up of other components
- will handle all HTML escaping in leaf components (components that do not render other components).
Component templates should only contain reusable UI-related code written in vanilla PHP.
Using vanilla PHP
- helps in keeping application logic out
- makes component templates more portable, so they can be used with tools like Pattern Lab
- makes onboarding easier for frontend developers not familiar with VuFind and PHP.
However, there are a few exceptions, listed below.
Component templates may include other components using the Laminas PhpRenderer::render($nameOrModel, $values = null)
method.
The file name should contain the component's path starting from the components
folder and ending in the component folder name.
Example:
<?= $this->render('components/molecules/navigation/finna-nav-item', $__item); ?>
Component templates should use the Laminas EscapeHtml
view helper for escaping data to use within an HTML body context.
Component templates should use the Laminas EscapeHtmlAttr
view helper for escaping data to use within an HTML attribute context.
Component templates should include additional CSS files using the Laminas HeadLink
helper.
Component templates should include JavaScript files using either the Laminas HeadScript
or InlineScript
view helper.
The file name should contain the full path starting from the components
folder.
Example:
<?php $this->headScript()->appendFile('components/organisms/navigation/finna-tabs-nav/finna-tabs-nav.js'); ?>
Component templates may use the Laminas HtmlAttributes
view helper to create new HtmlAttributesSet
objects.
Templates should support an $attributes
parameter variable for the outermost HTML element, adding the component's machine name as a class or setting it as an id.
Example:
<div<?= $this->htmlAttributes($attributes ?? [])->add('class', ['finna-panel', 'panel']) ?>>
Component templates should create image paths using the VuFind ImageLink
view helper.
Component templates should add translated strings for JavaScript using the VuFind JsTranslations
helper.
Component templates may use the VuFind TransEsc
view helper to display translated and escaped strings.
Component templates may use the VuFind Translate
view helper to display translated strings.
Component templates may use the Laminas Url
view helper to create a string representation of the routes defined in an application.
Component templates may have two kinds of variables: parameter variables, which are passed to the template in the render()
call, and local variables.
All parameter variables (exposed component properties) should be documented in the component's documentation file.
A double underscore prefix should be used for local variable names to differentiate them from parameter variables.
Example: $parameterVariable
, $__localVariable
.