-
Notifications
You must be signed in to change notification settings - Fork 2
CMS actions
Actions on a page allow you to access useful variables, objects and methods to be used when building your pages. You will notice that each of the eCommerce specific pages in the system such as Cart, Category, Product and so on, all have an action set.
For example the Category page will have an action set to shop:category. Expanded details on specific actions will be provided later on in this documentation.
To better understand actions, let's look at an example of an action and its use on the category page.
Click on the Editor button on the sidebar and then click on the Pages link under the Editor menu. Open the Edit Page form for the Category page by clicking on the Category line item.
As demonstrated in the previous screenshot, the action for this page is set to shop:category. The shop:category action prepares the category object for use in our page code.
If you look at the URL field on the category Edit Page form, you will see the following pattern which builds the page URL based on the hierarchy of the category selected and is pulled from the category object.
If you look in the content section for the category page, starting on line 9, You will see the following section of code:
<div class="product-list nine columns">
{% if not category %}
<h2>Category not found</h2>
<p>We are sorry, the requested category was not found.</p>
{% else %}
<div class="row">
{{
partial('shop-product-list', {
'products': products,
'empty_text': 'There are no products in this category.'
})
}}
</div>
{% endif %}
</div>
The line we are most concerned with for our example is the section beginning on line 10:
{% if not category %}
This if not statement is referencing the category object when the page loads to determine if the category name in the URL of the page being loaded actually exists as a category in the system. If it does not exist the category not found code is outputted.
For example let's load the following URL in our store for a category that does not exist.
your-store/category/pets
You will see that since the pets category does not exist, the category not found section of the code is outputted to the page.
If we navigate to the the Sporting Goods category page on our website, since the Sporting Goods category exists a list of products belonging to this category will be displayed on the page.