Objects
Objects in Twig contain attributes that output dynamic content on the given page.
For example, the product object contains an attribute called title
that can be used to output the title/name of the product being viewed.
Often, you may find that objects and their attributes are referred to as variables. These terms are used interchangeably.
To output the attribute of an object, the variable is wrapped in {{
and }}
, for example
{{ product.title }}
returns
Nike white trainers
The output of objects and their attributes can be modified with filters, for example
{{ product.title|capitalize }}
returns
Nike White Trainers
Filters are placed within an output tag (i.e. {{ }}
) and are denoted with the pipe character |
. Read more about filters.
The output of objects can also be modified, in a similar way, using functions.
Types of objects
There are essentially two types of objects available on ShopWired.
The Global objects
are a set of objects that are available on any template in your theme.
The Other objects
are only available on a specific template.
Global objects
The objects available globally on any template are:
global.theme
global.header
global.footer
global.basket
global.shipping_rate_id
global.shipping_country_id
global.wishlist
global.current_url
global.current_path
global.business
global.customer
global.currencies
global.brands
global.categories
global.social_links
global.info_message
global.currency_id
global.features.ajax_basket
featured_categories
featured_products
random_products
new_products
global.visitor
global.features.apps