Functions
Functions are convenience methods used to generate page content.
Functions can be used for operations such as returning min/max values and enabling code reuse. In addition to supported Twig functions, Square extensions provide additional functionality to interact with the site catalog and other site features and functionality.
In page templates, function calls are wrapped in {% %}
or {{ }}
. Some functions accept arguments. Functions are often used with filters.
- To execute a statement:
{% for i in function_name() %}
{{ i }},
{% endfor %}
- To evaluate an expression and output the result:
{{ function_name() }}
Supported functions
You can use the following functions in Square Online page templates.
Resource functions
Function | Description |
---|---|
item | Provides a single item from the site catalog. |
item_list | Provides an array of items from the site catalog. |
popular_items | Provides an array of items sorted by popularity. |
similar_items | Provides an array of items that are similar to the given item. |
category | Provides a single category from the site catalog. |
category_list | Provides an array of categories from a site catalog. |
category_hierarchy | Provides the nesting structure of a site’s categories. |
location | Provides a single location from the site’s store settings. |
location_list | Provides an array of locations from the site’s store settings. |
location_courier_quote_list | Provides an array of delivery fee information for nearby locations. |
cart | Provides the data for the current session’s shopping cart. |
customer_account | Provides the data for the logged in customer. |
store_info | Provides the store’s information. |
resource | Provides the specified resource. |
video | Renders a video player for the video. |
paginate_meta | Get the pagination context for a resource. |
Templates can also use the schema
tag to access resources from the site catalog. For more information, see How to: Use Resources in Templates.
Link functions
Function | Description |
---|---|
link | Generates an href compatible string given the link type. |
item_link | Generates a site link to a given item’s theme page. |
category_link | Generates a site link to a given category’s theme page. |
page_link | Generates a link to a Square Online website page. |
custom_page_link | Generates a link to a Square Online custom site page. |
Other functions
Function | Description |
---|---|
head_trackers | Outputs tracking libraries and scripts set in Square’s configuration settings that should be rendered within a site’s head tags. |
body_trackers | Outputs tracking libraries and scripts set in Square’s configuration settings that should be rendered within a site’s body tags. |
customer_account_url | Outputs the URL customers will use to access their account portal, for viewing past/existing orders and current account settings. |
customer_accounts_login | Used in the login flow for a customer account. |
register_asset | Registers a JS or CSS asset for loading within the page. |
supported_image_sizes | Outputs an array of image sizes supported by the site. |
Twig functions | Supported core Twig functions. |
Square also provides the following script dependencies:
forms_script
- Used with the form tag.customer_accounts_script
- Used with the customer_accounts_login tag.