hi all, i have a ‘url’ metafield type in which i’d need to make ‘dynamic’
This metafield type requires a https:// scheme and the original value is like
https://domain.com/pages/xyz
I have 2 countries and languages and i’d prefer to not translate in the translate and adapt every single url but making this ‘dynamic’ like
https://domain.com/dynamicCountry/dynamicLanguage/pages/xyz
or even just
https://dynamicdomain%country&language/pages/xyz
the theme is already configured to recognize country and language so my problem here is just that the URL type metafield requires a https:// start and that isn’t allowing me to add only the /pages/xyz that would inheritate the domain/country/language as done in other page.
any thoughts? thanks in advance
1 Like
thanks! this seems a code for the theme, but i’d need to add this in a ‘url’ metafield placeholder - wdyt?
i think you can use Metafields API for that. You’ll need a small app or a serverless function to do this. The process would be:
- When a product (or whatever object the metafield is attached to) is created or updated, your app/function would trigger
- It would retrieve the country and language (likely from the request.locale if your app is theme-based or from other context if it’s external)
It would construct the full URL: https://{{domain}}/{{country}}/{{language}}/{{page_path}} (where page_path comes from wherever you’re storing that part)
- It would then use the Metafields API to update the metafield with this dynamically generated URL
hope that helps!