Menu Close

Get Support From ShopWired Close

All systems fully operational

Subscribe To Updates
Prefer To Live Chat? Chat directly with ShopWired support Available from 9.00am to 6.00pm Monday to Friday Quickest response time
Send A Message
Response within 24 hours

Menu Close

Menu

Functions

Functions perform a specific purpose on our platform in order to print dynamic content.

For example if the price of a product is set at £3.90 if you use the variable {{ product.price }} the price will be outputted as 3.9.

To return the price of a product with the appropriate currency symbol and formatted to 2 decimal places (with a thousand separator) you should use {{ currency_value(product.price) }}, which will return £3.90.

The function here is quite similar to a Twig filter.


asset_url

To reference the full URL of a file such as an image or CSS document within your theme's files you can use the asset_url function.

You'll need to include the full path of the file, e.g.

{{ asset_url('images/filename.png') }}

If you want to reference a folder/directory you can do so by adding an argument to the function, e.g.

{{ asset_url('images') }}

featured_categories

You can use the featured_categories function in order to return the categories that have been chosen as featured categories.

For example...

{% include 'partials/categories.twig' with { 'categories': featured_categories } %}

Will return, using the categories.twig file, the featured categories in an account.

You can place arguments into the function, such as whether to show a category's description, e.g.

{% include 'partials/categories.twig' with { 'categories': featured_categories, 'show_description': true } %}

Will set the show_description argument to true.

This would then be able to be referenced on the categories.twig file, testing whether the argument was true and if so, showing the category description, e.g.

{% if show_description %}
    <span class="description">
        {{ category.description }}
    </span>
{% endif %}

featured_categories is an array which means that you can loop through featured categories if you wish to, e.g.

{% for category in featured_categories %}
    {{ category.title }}
{% endfor %}

Whether there are featured categories set can be determined using the length filter, e.g.

{% if featured_categories|length %}
    <div id="featured-categories">
        {% for category in featured_categories %}
            {{ category.title }}
        {% endfor %}
    </div>
{% endif %}

featured_products

The featured_products function is very similar to the featured_categories function. It is an array of featured products set on an account.


new_products

The new_products function is very similar to the featured_products function and will return an array of new products (marked with the new indicator).


blog_posts

The blog_posts function is an array of blog posts created on an account and uses the blog post object.

It could be used, for example, to show some of the recent blog posts on a website's home page. To avoid displaying all blog posts, you can set the number of blog posts you want to display, e.g.

{% set blog_posts = blog_posts(3) %}
{% if blog_posts %}
    <div class="blog-posts">
        <h3>Our latest news...</h3>
        {% for blog_post in blog_posts %}
            <a href="{{ blog_post.url }}">{{ blog_post.title }}</a>
        {% endfor %}
    </div>
{% endif %}

basket_items

The basket_items function is an array of items currently in the shopping basket and uses the basket item object.


currency_url

The currency_url function returns the proper URL that will change the currency being displayed on the website (when using the currency app), e.g.

{{ currency_url(currency.id) }}

Text snippets

This only applies if you are using the undocumented HTML text snippets feature (which is not enabled on accounts by default).

{% set textSnippet = snippet(snippet_id) %}

You can use this code to output the contents of an HTML text snippet by entering the ID of the text snippet into the code.

To obtain the snippet ID, visit the text snippet in your browser. The number at the end of the URL is the text snippet ID.