category_hierarchy Function

Provides the nesting structure of a site’s categories.

The function takes three optional parameters:

  1. location_id
  2. Parent category_id
  3. square_online_id toggle

For example output, see CategoryHierarchy Resource.

Here is an example of recursively displaying a category hierarchy

{% macro display_category(category) %}
	<div style="padding-left: 10px">
		<p>{{ category.name }}</p>
		{% for child in category.children %}
			{{ _self.display_category(child) }}
		{% endfor %}
	</div>
{% endmacro %}

{% for category in category_hierarchy() %}
	{{ _self.display_category(cat) }}
{% endfor %}

Note that the categories in the category_hierarchy do not contain their associated items. Here is an example of fetching a category’s items:

{% for my_category in category_hierarchy() %}
	{% for item in category(my_category.square_online_id).items %}
		{{ item.name }}
	{% endfor %}
{% endfor %}