So I’ve setup a list of single line text values metafield to achieve a table layout. The user would enter their values like so:
Row 1|Row 1 Value
Row 2|Row 2 Value
Row 3|Row 3 Value
Then in the loop I would split by | to get the two values.
Now, I’m trying to use this metafield as a dynamic source into a text input within a block.
The issue I’m having is I’m unable to loop over these values in the metafield, it seems to be be combining the values into a single string separated by commas. So doing the following:
<h3>block.settings.table_metafield: {{ block.settings.table_metafield }}</h3>
// Result
block.settings.table_metafield: Row 1|Row 1 Value,Row 2|Row 2 Value,Row 3|Row 3 Value
And then I can’t even do a split by comma incase my values contain a comma.
Is there a workaround here to achieve this?
Essentially this is a section to create some product tabs, with two block types, table and richtext.
The user can then populate these using dynamic sources from a product.
{
"type": "text",
"id": "table_metafield",
"label": "t:sections.product-tabs.blocks.table.settings.table_metafield",
"info": "Select a metafield as the dynamic source, this metafield must be a list of single line text fields. Each single line text field must be separated by a '|' which creates the row title and the row value, e.g. Bag size|60 liters"
}
Tried to test this and had some additional findings. When using the List Type Text Metafield as a dynamic value in the Text setting input. A grammatical assumption is made & the word ‘and’ is inserted to join the last item to the sentence, as well as the items being joined by a comma.
By default, the customizer will set product.metafields.namespace.key | metafield_text in the JSON template. In this case, the returned data is the comma separated (+ and at the end) string.
You can also manually edit the template JSON to use the metafield value product.metafields.namespace.key.value as dynamic source. In this case, the returned data is a concatenated string.
Of course, using hardcoded metafield access, we have the expected result, an array of the different text elements.
I would argue that the second test case should return an array, this would solve the issue but there should be a way of selecting between | metafield_text and .value as a consequence.