ride/web-template-smarty

Smarty template integration for the base web application of the Ride framework

2.0.0 2024-04-19 13:14 UTC

README

This module adds template blocks, functions and modifiers for a Ride application to Smarty.

Block functions

[Smarty docs]

isGranted

Parse block content if the specified route/url/permission is allowed.

Parameter Type Description
route String Path to check for allowance.
url String URL to check for allowance.
permission String Permission code to check for allowance.
strategy String AND or OR when checking more then one of the above checks.
var String Variable to assign the result to. (true if this block content will be printed, false otherwise)
{isGranted permission="cms.node.varnish.manage"}
  ...
{/isGranted}

Note: The content of this block is always rendered. If the content is used for logic, assign the grant to a var and use an if statement.

isNotGranted

Parse block content if the specified route/url/permission is not allowed.

Parameter Type Description
route String Path to check for allowance.
url String URL to check for allowance.
permission String Permission code to check for allowance.
strategy String AND or OR when checking more then one of the above checks.
var String Variable to assign the result to. (true if this block content will be printed, false otherwise)
{isNotGranted permission="cms.node.varnish.manage"}
  ...
{/isNotGranted}

Note: The content of this block is always rendered. If the content is used for logic, assign the grant to a var and use an if statement.

Template functions

[Smarty docs]

apiMethodParameters

{apiMethodParameters method= url= namespace= classes=}

apiType

{apiType type= url= method= html= link= namespace= classes=}

image

Return the URL of a transformed image.

Parameter Type Description
src String Source url or file for this image.
default String Fallback for src parameter.
transformation String Name of the transformation.
var String Variable name to assign this URL to.
thumbnail --- Deprecated

⚠️ Transformations may require additional parameters.

For more information about the transformations and their parameters, check out ride-lib-image.

{image src=$content->image var='image' transformation='crop'}

parsley

Adds parsley data attributes to the attributes of a form widget.

Parameter Type Description
type string Type of the form row widget
validators Array Validators of a form row
var String Variable name to assign the updated attributes to.
{$widget = $formRow->getWidget()}
{parsleyAttributes attributes=$widget->getAttributes() type=$widget->getType() var="attributes"}

tableVars

Add these FormTable variables to the template:

  • $tableNameField
  • $tableActionField
  • $tableIdField
  • $tableOrderField
  • $tableSearchQueryField
  • $tablePageRowsField
{tableVars}

translate

Translate a key using the i18n translator.

Parameter Type Description
key String Translation key.
locale String Translation locale.
n Integer Number of items for a translation that describes multiple items.
var String Variable name to assign the translated key to.
{translate key='label.submit' locale='nl'}

⚠️ When simply translating a key, using the {$key|translate} modifier syntax is preferred.

url

Create an URL.

Parameter Type Description
id String Route ID.
parameters Array Path arguments for the URL.
query Array Query parameters.
separator String Seperator for query parameters. (defaults to &)
var String Variable name to assign the URL to.
object Boolean Return URL Object instead of String. (defaults to false)
{url id='api.search' var='searchUrl'}

Modifiers

[Smarty docs]

decorate

Parameter Type Description
String ID of the decorator.

Common decorator IDs: storage.size / time / date.format / file / file.extension / file.size

{$content->data->getDatePublished()|decorate:'time'}

safe

Modify a string value to safely use it as a file name, URL, id etc.

{'Unsafe string!'|safe} {* result: unsafe-string *}

translate

Parameter Type Description
Array Variables to be replaced in the translation.
{'label.fields.required'|translate}

Related Modules

Installation

You can use Composer to install this application.

composer require ride/web-template-smarty