Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
I have a metaobject called "brand" within a metafield "created_by" and I want to use the slug of the "name" key of the brand to create a link to the brand page template. Example link... https://www.beforeourtime.com/pages/brand/colors-greys
"colors & greys" is the name of a brand. This is the metaobject definition... https://snipboard.io
This is how I reference the brand name on my product page template...
{{ product.metafields.custom.created_by.value.name }}
Solved! Go to the solution
This is an accepted solution.
Hi,
1. Create a Metafield-->Assign a Value(This value could be a string that you want to use as a part of the URL slug.)
2. Generate the slug using the metafield value, you can use liquid code. Here's an example for a product:
{% assign product_metafield = product.metafields.namespace.key %}
{% assign slug = product_metafield | handle %}
In this code:
product.metafields.namespace.key should be replaced with the actual namespace and key of your metafield.
handle is a filter in liquid that converts a string into a URL-friendly slug. It removes spaces, converts to lowercase, and replaces special characters.
Use the generated Slug in Your URLs
Example
custom product URL
<a href="/products/{{ slug }}">{{ product.title }}</a>
If you still need help from our side you can contact us through given details at signature
This is an accepted solution.
Hi,
1. Create a Metafield-->Assign a Value(This value could be a string that you want to use as a part of the URL slug.)
2. Generate the slug using the metafield value, you can use liquid code. Here's an example for a product:
{% assign product_metafield = product.metafields.namespace.key %}
{% assign slug = product_metafield | handle %}
In this code:
product.metafields.namespace.key should be replaced with the actual namespace and key of your metafield.
handle is a filter in liquid that converts a string into a URL-friendly slug. It removes spaces, converts to lowercase, and replaces special characters.
Use the generated Slug in Your URLs
Example
custom product URL
<a href="/products/{{ slug }}">{{ product.title }}</a>
If you still need help from our side you can contact us through given details at signature
Thanx Bro!
Starting a B2B store is a big undertaking that requires careful planning and execution. W...
By JasonH Sep 23, 2024By investing 30 minutes of your time, you can unlock the potential for increased sales,...
By Jacqui Sep 11, 2024We appreciate the diverse ways you participate in and engage with the Shopify Communi...
By JasonH Sep 9, 2024