related_items
This component fetches related items of a specific source item, such as a Product that has had Related Products assign to it.
{% component type: "related_items", source: "Products", itemId: "<Item ID>" %}
Parameters and Options
related_items
This is the name of the entity that needs to be used for the component retrieving function.
<Module name/ID>
<Item ID>
<path/to/layout>
If an empty string, nothing will be rendered.
If paramater is not included, the default virtual layout will be rendered (see below).
id
parentid
name
weighting
url
urlslug
releasedate
expirydate
LastUpdatedDate
Author
ItemCategories
ItemTags
<CustomPropertyName>
...and any other top level properties available for the module
Remove spaces from custom property names here.
ASC (default)
DESC
ASC
sorts the items in ascending order while DESC
sorts in descending order (based on alpha/numeric or date sorting).If empty or not present, alpha/numeric sorting will be used.
10 (default)
<integer>
item
collection (default)
item
returns each item iteratively, one after another, for output (generally, output to a container element with no need for looping through the data).collection
returns all items as one collection for output (your container element and looping logic would be handled in the Components Layout).<yourLiquidVariableName>
Your collectionVariable value must only contain English letters, numbers or underscores. Spaces or special characters are not supported.
Liquid Output
The below example has 2 related items
and is the default structure you will get from this Component.
{
"Params": {
"type": "related_items",
"source": "Products",
"itemid": "2535",
"layout": "",
"collectionvariable": "relatedCollection"
},
"Pagination": {
"CurrentPage": 1,
"ItemsPerPage": 10,
"NumberOfPages": 1,
"TotalItemsCount": 2
},
"Parent": {
"Id": 2554,
"Name": "related_items",
"Url": "/component-types/related_items",
"Url_List": [
"/component-types/related_items"
],
"UrlSlug": "related_items",
"ParentId": 2127,
"ParentId_List": [
2127
],
"ParentName": "Liquid Components",
"ParentUrl": "/component-types",
"TemplateName": "Docs Template",
"Module_Alias": "DocumentationPost",
"Module_ID": 1870,
"Enabled": true,
"ReleaseDate": "2018-09-20T00:00:00",
"ExpiryDate": "2099-12-10T00:00:00",
"SiteSearchKeywords": [],
"Description": "\n{% component type: \"snippet\", alias: \"code_block_processor\", data: \"{{data}}\", lang: \"liquid\" %}\n\n{% component type: \"snippet\", alias: \"section_parameters\" %}\n\n{% component type: \"json\", source_type:\"string\", source:\"{{tabularData}}\", layout:\"/snippets/tabularJSON.layout\" %}\n</section>\n\n{% component type: \"snippet\", alias: \"section_output\" %}\n\n{% component type: \"related_items\", source: \"Products\", itemId: \"2535\", layout: "", collectionVariable: \"relatedCollection\" %}\n\n<p>The below example has 2 related <code>items</code> and is the default structure you will get from this Component.</p>\n{% component type: \"snippet\", alias: \"code_block_processor\", data: \"{{relatedCollection}}\", lang: \"json\" %}\n</section>\n\n{% component type: \"snippet\", alias: \"section_virtual_layout\" %}\n<p>Based on the above example, if not using any custom layout or collection, the default virtual layout will output as a list of related items:</p>\n\n{% component type: \"snippet\", alias: \"code_block_processor\", data: \"{{data}}\", lang: \"html\" %}\n<p>Rendering the list:</p>\n{% component type:\"related_items\", source: \"Products\", itemId: \"2535\" %}\n</section>\n\n{% component type: \"snippet\", alias: \"section_accessing_data\" %}\n<p>This data is also accessible directly on the Page or Template via a Liquid Collection by adding <code>collectionVariable</code> to the Component.</p>\n\n<p>An example using <code>collectionVariable</code> with value \"relatedCollection\":</p>\n\n{% component type: \"snippet\", alias: \"code_block_processor\", data: \"{{data}}\", lang: \"liquid\" %}\n\n<p><em>Accessing a specific item within the collection. In this case the first item (zero based index), which in our example would render the value <code>DEMO product 2</code></em></p>\n\n{% component type: \"snippet\", alias: \"code_block_processor\", data: \"{{data}}\", lang: \"liquid\" %}\n</section>",
"Weighting": 810,
"DisableForSiteSearch": false,
"CreatedByMemberId": "0",
"ItemCategories": [],
"ItemCategoryIdList": [],
"ItemTags": [
"Ecommerce"
],
"Author": 0,
"Author_Name": "",
"Author_Url": "",
"Item_Rating": 0,
"Active": true,
"IgnoreUpdates": true,
"UpdatesLog": "<ul><li>All new article</li></ul>",
"ExternalResources": "",
"AdditionalRelatedArticle": 0,
"AdditionalRelatedArticle2": 0,
"Authors": "2418",
"ShowPageForSearchEngine": true,
"MetaTitle": "",
"SEOTitle": "",
"MetaDescription": "This component fetches related items of a specific source item, such as a Product that has had Related Products assign to it.",
"CanonicalLink": "",
"SocialMetaTags": "",
"SeoPriority": 0.8,
"EnableAMP": false,
"AMPContent": "",
"OpenGraphProperties": {
"title": "",
"type": "",
"url": "",
"locale": "",
"image": ""
},
"ExternalId": 0,
"Params": {
"type": "snippet",
"alias": "section_output",
"data": "\n{% component type: \"related_items\", source: \"Products\", itemId: \"<Item ID>\" %}\n",
"lang": "liquid",
"name": "SECTION Output",
"content": "<section id=\"secOutput\">\n <h2>Liquid Output</h2>",
"enabled": true,
"required": "true",
"values": "item,collection <em>(default)</em>",
"altname": "itemId",
"description": "The module item ID (specific Product) the data is to be sourced from"
}
},
"Items": [
{
"Id": 2536,
"Name": "DEMO product 2",
"Url": "/catalogs/demo-product-2",
"Url_List": [
"/catalogs/demo-product-2"
],
"UrlSlug": "demo-product-2",
"ParentId": 2485,
"ParentId_List": [
-1
],
"ParentName": "",
"ParentUrl": "",
"TemplateName": "",
"Module_Alias": "Product",
"Module_ID": 2485,
"Enabled": true,
"ReleaseDate": "2020-05-05T23:00:00",
"ExpiryDate": "2099-12-11T13:00:00",
"SiteSearchKeywords": [],
"Description": "<p>Sample product for the ecommerce store.</p>",
"Weighting": 0,
"DisableForSiteSearch": false,
"SKUCode": "DEMO2",
"SmallImage": "/images/template-detail-crafter-mobile@2x.png",
"LargeImage": "/images/template-detail-crafter-desktop@2x.jpg",
"OnSale": false,
"IsGiftVoucher": false,
"ProductWeight": 0.0000,
"ProductWidth": 0.0000,
"ProductHeight": 0.0000,
"ProductDepth": 0.0000,
"EnableDropShipping": false,
"UnitType": "",
"MinimumUnits": 0,
"MaximumUnits": 0,
"RecurringType": "None",
"IsShippable": true,
"IsDownloadable": false,
"NumberOfPossibleDownloads": 0,
"Supplier": 0,
"Price": 0.0,
"PriceHtml": "<span data-cms_product_data_price=\"2536\">0.00</span>",
"priceWithTax": 0.0,
"priceWithTaxHtml": "<span data-cms_product_data_price_with_tax=\"2536\">0.00</span>",
"RecommendedPriceWithTax": 0.0,
"RecommendedPriceWithTaxHtml": "<span data-cms_product_data_recommended_price_with_tax=\"2536\">0.00</span>",
"RecommendedPrice": 0.0,
"RecommendedPriceHtml": "<span data-cms_product_data_recommended_price=\"2536\">0.00</span>",
"EnableInventoryControl": false,
"HasGeneratedInventoryProducts": false,
"InStockHtml": "<span data-cms_product_data_in_stock=\"2536\"></span>",
"IsHide": false,
"InStock": 0,
"IsDisable": false,
"taxRate": 0.0,
"IsGroupedProduct": true,
"decimalsQuantity": 0,
"VolumeDiscount": [
{
"Price": 0.0,
"Quantity": 0
}
],
"ProductDataJSON": {
"itemId": 2536,
"maximumUnits": 0,
"minimumUnits": 0,
"recommendedPrice": 0.0,
"QuantityThreshold": [
{
"Price": 0.0,
"Quantity": 0
}
],
"inStockTotal": null,
"prices": {
"0": 0.0
},
"enablePreOrder": false,
"variations": null,
"attributes": {},
"options": {},
"taxRate": 0.0,
"taxInPercent": 0.0
},
"ProductDataJsonHTML": "<script>initEcommerceProductPriceVariations(2536,{\"itemId\":2536,\"maximumUnits\":0,\"minimumUnits\":0,\"recommendedPrice\":0.0,\"QuantityThreshold\":[{\"Price\":0.0,\"Quantity\":0}],\"inStockTotal\":null,\"prices\":{\"0\":0.0},\"enablePreOrder\":false,\"variations\":null,\"attributes\":{},\"options\":{},\"taxRate\":0.0,\"taxInPercent\":0.0});</script>",
"CreatedByMemberId": "0",
"ItemCategories": [],
"ItemCategoryIdList": [],
"ItemTags": [],
"Author": 0,
"Author_Name": "",
"Author_Url": "",
"Item_Rating": 0,
"MyCustomProperty": null,
"ShowPageForSearchEngine": false,
"MetaTitle": "",
"SEOTitle": "",
"MetaDescription": "",
"CanonicalLink": "",
"SocialMetaTags": "",
"SeoPriority": 0.5,
"EnableAMP": false,
"AMPContent": "",
"OpenGraphProperties": {
"title": null,
"type": null,
"url": null,
"locale": null,
"image": null
},
"ExternalId": 0,
"Params": {}
},
{
"Id": 2563,
"Name": "DEMO Product 3",
"Url": "/catalogs/demo-product-3",
"Url_List": [
"/catalogs/demo-product-3"
],
"UrlSlug": "demo-product-3",
"ParentId": 2485,
"ParentId_List": [
-1
],
"ParentName": "",
"ParentUrl": "",
"TemplateName": "",
"Module_Alias": "Product",
"Module_ID": 2485,
"Enabled": true,
"ReleaseDate": "2020-05-19T23:00:00",
"ExpiryDate": "2099-12-11T13:00:00",
"SiteSearchKeywords": [],
"Description": "",
"Weighting": 0,
"DisableForSiteSearch": false,
"SKUCode": "7067ce22-6b5d-4bdb-80e6-b878ca0b31f2",
"SmallImage": "",
"LargeImage": "",
"OnSale": false,
"IsGiftVoucher": false,
"ProductWeight": 0.0000,
"ProductWidth": 0.0000,
"ProductHeight": 0.0000,
"ProductDepth": 0.0000,
"EnableDropShipping": false,
"UnitType": "",
"MinimumUnits": 0,
"MaximumUnits": 0,
"RecurringType": "None",
"IsShippable": true,
"IsDownloadable": false,
"NumberOfPossibleDownloads": 0,
"Supplier": 0,
"Price": 0.0,
"PriceHtml": "<span data-cms_product_data_price=\"2563\">0.00</span>",
"priceWithTax": 0.0,
"priceWithTaxHtml": "<span data-cms_product_data_price_with_tax=\"2563\">0.00</span>",
"RecommendedPriceWithTax": 0.0,
"RecommendedPriceWithTaxHtml": "<span data-cms_product_data_recommended_price_with_tax=\"2563\">0.00</span>",
"RecommendedPrice": 0.0,
"RecommendedPriceHtml": "<span data-cms_product_data_recommended_price=\"2563\">0.00</span>",
"EnableInventoryControl": false,
"HasGeneratedInventoryProducts": false,
"InStockHtml": "<span data-cms_product_data_in_stock=\"2563\"></span>",
"IsHide": false,
"InStock": 0,
"IsDisable": false,
"taxRate": 0.0,
"IsGroupedProduct": true,
"decimalsQuantity": 0,
"VolumeDiscount": [
{
"Price": 0.0,
"Quantity": 0
}
],
"ProductDataJSON": {
"itemId": 2563,
"maximumUnits": 0,
"minimumUnits": 0,
"recommendedPrice": 0.0,
"QuantityThreshold": [
{
"Price": 0.0,
"Quantity": 0
}
],
"inStockTotal": null,
"prices": {
"0": 0.0
},
"enablePreOrder": false,
"variations": null,
"attributes": {},
"options": {},
"taxRate": 0.0,
"taxInPercent": 0.0
},
"ProductDataJsonHTML": "<script>initEcommerceProductPriceVariations(2563,{\"itemId\":2563,\"maximumUnits\":0,\"minimumUnits\":0,\"recommendedPrice\":0.0,\"QuantityThreshold\":[{\"Price\":0.0,\"Quantity\":0}],\"inStockTotal\":null,\"prices\":{\"0\":0.0},\"enablePreOrder\":false,\"variations\":null,\"attributes\":{},\"options\":{},\"taxRate\":0.0,\"taxInPercent\":0.0});</script>",
"CreatedByMemberId": "0",
"ItemCategories": [],
"ItemCategoryIdList": [],
"ItemTags": [],
"Author": 0,
"Author_Name": "",
"Author_Url": "",
"Item_Rating": 0,
"MyCustomProperty": null,
"ShowPageForSearchEngine": false,
"MetaTitle": "",
"SEOTitle": "",
"MetaDescription": "",
"CanonicalLink": "",
"SocialMetaTags": "",
"SeoPriority": 0.5,
"EnableAMP": false,
"AMPContent": "",
"OpenGraphProperties": {
"title": null,
"type": null,
"url": null,
"locale": null,
"image": null
},
"ExternalId": 0,
"Params": {}
}
]
}
Virtual Layout
Based on the above example, if not using any custom layout or collection, the default virtual layout will output as a list of related items:
<ul>
{% for item in this.items %}
<li>
<a href="{{item.url}}" title="{{item.name}}">{{item.name}}</a>
</li>
{% endfor %}
</ul>
Rendering the list:
Accessing the Data
JSON Output
You can output the full JSON for your component data by referencing the root Liquid object {{this}}
in your module’s layouts, or directly on your page, if using the collectionVariable
parameter in your component tag.
For example:
{% component type: ... collectionVariable: "myData" %}
You can then render the JSON like so:
{{myData}}
For more details on using this approach, see Part 2 of the free ‘Learning Liquid Course’.
Rendering Property Values
This data is also accessible directly on the Page or Template via a Liquid Collection by adding collectionVariable
to the Component.
An example using collectionVariable
with value "relatedCollection":
{% component type:"related_items", source: "Products", itemId: "2535", collectionVariable: "relatedCollection" %}
Accessing a specific item within the collection. In this case the first item (zero based index), which in our example would render the value DEMO product 2
{{relatedCollection.items[0]['Name']}}