Meta Keywords on single line

Hi there, my first post…

My code:

<meta name="keywords" id="colours" dmx-repeat:repeatcolour="productdetails.data.productquery.colours" dmx-bind:content="productdetails.data.colourquery.colourName">
<!--start dmx-repeat:repeatcolour=productdetails.data.productquery.colours--><meta name="keywords" dmx-bind:content="{{colourName}}" content="Black"><meta name="keywords" dmx-bind:content="{{colourName}}" content="Blue"><meta name="keywords" dmx-bind:content="{{colourName}}" content="Brown"><meta name="keywords" dmx-bind:content="{{colourName}}" content="Green"><meta name="keywords" dmx-bind:content="{{colourName}}" content="Grey"><meta name="keywords" dmx-bind:content="{{colourName}}" content="Orange"><meta name="keywords" dmx-bind:content="{{colourName}}" content="Pink"><meta name="keywords" dmx-bind:content="{{colourName}}" content="Purple"><meta name="keywords" dmx-bind:content="{{colourName}}" content="Red"><meta name="keywords" dmx-bind:content="{{colourName}}" content="White"><meta name="keywords" dmx-bind:content="{{colourName}}" content="Yellow"><!--end dmx-repeat:repeatcolour=productdetails.data.productquery.colours-->

How do I get it to output as:

name="keywords" dmx-bind:content="{{colourName}}" content="Black, Blue, Brown, Green etc..."

Thanks in advance for any help.

Justin

Assuming productdetails.data.productquery.colours is the array, then try using array.join() instead of a repeat. The code would look something like:

<meta name="keywords" content="{{ productdetails.data.productquery.colours.map(colourName).join(', ') }}">

Where

  • map(colorname) extracts just the colour names from the array
  • join(', ') merges them into a single comma‑separated string.
1 Like

Hi Ben, thanks for your reply.

I have changed the code but I get a blank output.

i.e.

<meta name="keywords" content="{{ productdetails.data.productquery.colours.map(colourName).join(', ') }}">

I am wondering if a js library is missing from my installation.

Justin

Can you show the output of the following expression?

{{productdetails.data.productquery.colours}}

I have it on the page further down like this:

<!--start dmx-repeat:repeatcolour=productdetails.data.productquery.colours--><span class="badge bg-secondary style63" style="--bs-badge-border-radius: 2px;" id="colours">Blue</span><span class="badge bg-secondary style63" style="--bs-badge-border-radius: 2px;" id="colours">Green</span><span class="badge bg-secondary style63" style="--bs-badge-border-radius: 2px;" id="colours">Grey</span><!--end dmx-repeat:repeatcolour=productdetails.data.productquery.colours-->

Actually, if I just show this I get: [object Object],[object Object],[object Object]

Can you simply post a screenshot of what your structure is for this server action/db query from the Network > XHR tab in the dev tools of your browser?

  1. {query: {productID: 30, productSuspended: 0, productSEO: "perfect-men-polo-180g-in-green",…},…}

    1. colourquery: [{productID: 30, colourName: "Blue"}, {productID: 30, colourName: "Green"},…]

      1. 0: {productID: 30, colourName: "Blue"}

      2. 1: {productID: 30, colourName: "Green"}

      3. 2: {productID: 30, colourName: "Grey"}

    2. groupquery: {id: 77, productID: 30, groupName: "Clothing (Polo Shirt) Products"}

      1. groupName: "Clothing (Polo Shirt) Products"

      2. id: 77

      3. productID: 30

    3. keywordquery: {keywordName: "PERFECT", keywordScore: 12, productID: 30}

      1. keywordName: "PERFECT"

      2. keywordScore: 12

      3. productID: 30

    4. productquery: {productID: 30, productSuspended: 0, productSEO: "perfect-men-polo-180g-in-green",…}

      1. colours: [{productID: 30, colourName: "Blue"}, {productID: 30, colourName: "Green"},…]

        1. 0: {productID: 30, colourName: "Blue"}

        2. 1: {productID: 30, colourName: "Green"}

        3. 2: {productID: 30, colourName: "Grey"}

      2. groups: [{productID: 30, groupName: "Clothing (Apparel) Products", id: 79},…]

      3. imageLarge: "https://www.promotional-images.co.uk/prodimages/ACC-030016/S11346-AG-lg.jpg"

      4. imageThumb: "https://www.promotional-images.co.uk/prodimages/ACC-030016/S11346-AG-lg-sm.jpg"

      5. keywords: [{keywordName: "180G", keywordScore: 10, productID: 30},…]

        1. 0: {keywordName: "180G", keywordScore: 10, productID: 30}

        2. 1: {keywordName: "Green", keywordScore: 10, productID: 30}

        3. 2: {keywordName: "MEN", keywordScore: 10, productID: 30}

        4. 3: {keywordName: "PERFECT", keywordScore: 12, productID: 30}

        5. 4: {keywordName: "POLO", keywordScore: 10, productID: 30}

      6. productDescription: "Sols Perfect Men, Mens Polo Shirt, 100% Combed Ringspun Cotton Piquã© 180, Rib 1X1 Collar & Cuffs, Reinforcing Tape on Neck, Short Sleeves, Pearlised Tone on Tone 2 Button Placket, Cut & Sewn, Spare Button on the Inside Seam, (1) Ash : 98 % Cotton & 2 % Viscose, (2) Grey Melange : 85 % Cotton & 15 % Viscose, (3) Charcoal Melange : 60 % Cotton & 40 % Polyester, (4) Heather Oxblood : 60% Cotton & 40% Polyester, (5) Heather Denim : 60% Cotton & 40% Polyester. About Sizes Matching, Please Refer to the Size Chart in the Product Documentation Section. Minimum Quantities Apply."

      7. productID: 30

      8. productMinPrice: "5.00"

      9. productName: "PERFECT MEN POLO 180G in Green"

      10. productPrice: "£5.00 to £7.49"

      11. productRef: "SC00491662"

      12. productSEO: "perfect-men-polo-180g-in-green"

      13. productSuspended: 0

      14. productType: "Polo Shirt"

      15. productTypeSEO: "polo-shirt"

    5. query: {productID: 30, productSuspended: 0, productSEO: "perfect-men-polo-180g-in-green",…}

I think i I have gone mad with the queries replications…

So you need to use the values formatter:

<meta name="keywords" id="colours" dmx-bind:content="productdetails.data.colourquery.values('colourName')">

It worked… thank you!