Hello All,
So I’ve been trying to get our SEO partial to auto populate/pull the price values set within the product JSON files.
Solution Ideas:
- Pass only the required values from within $products OR directly from the .JSON data file. This is the most ideal option as there’s only 1/2 needed values.
The below dev setup is related to the attempted second solution. Originally I tried to pass just certain values from $product or the JSON files but not sure if the formatting of my JSON file is causing the issue with this.
-
Pass the .site.params needed to populate the SEO partial along with $products.
In dev setup. Due to the below dev setup causing issues with site.params not working within the SEO partial. -
MD page has custom layout
+++
title = “Card”
type = “products”
layout = “tttoolkit”
images = [ “https://domain.ard_new_.jpg” ]
+++ -
Layout sets $product variable which is the JSON product details & adds in header partial . This is then ranges the product data variable ($product) to “product-button.html” which populates the JSON product data within a button (all working). I then also range that same variable ($product) to the SEO partial which populates the price (.price) stored within in $product.
{{ $product := where .Site.Data.products.cards “id” “card-12” }}
{{ partial “header-product.html” . }}
{{ range $product }}{{ partial “seo_product” . }}{{ end }}<>{{ range $product }} {{ partial "product-button.html" . }} {{ end }} {{ .Content }}Issue: With the above method, now i’m using the range $products, all of the .site params don’t work within the “seo_product” partial.
Other code:
SEO Partial (seo_product)
<script type="application/ld+json"> { "@context" : "http://schema.org", "@type" : "Product", "mainEntityOfPage": { "@id": "{{ .Permalink }}" }, "image": { "@type": "ImageObject", "url": "{{ if isset .Params "images" }}{{ range .Params.images }}{{ . }}{{ end }}{{ else}}{{ .Site.Params.defaultimage }}{{ end }}" }, "name" : "{{ .Title }}", "description" : "{{ if .Description }}{{ .Description }}{{ else }}{{if .IsPage}}{{ .Summary }}{{ end }}{{ end }}", "url" : "/{{ ..Permalinkl }}", "brand" : "Brand", "sku" : "", "offers": { "@type": "Offer", "availability": "http://schema.org/InStock", "price": "{{ .price}}", "priceCurrency": "GBP" } } </script>
JSON data file
Contains multiple products within the following syntax[{ "id": "product-id", "name": "Card", "price": "17.99", "weight": "17.99", "image": "/images/kit-tools/card.jpeg", "description": "Card", "url": "/shop-cards/", "producturl": "/shop-cards/card", "custopt":"0", "shippable": "true" }, (*This then repeats per product*)
Anyone able to help me with this ? The first solution being would be the most ideal.