I currently have html dropdown option selects for price calculation and I want to replace them with this hugo range dropdown option select solution:
---
option:
sizes: ["small","med","large"]
color: ["red","blue","black"]
---
{{ range $variantName, $value := .Params.option }}
{{ if len $value }} <!-- check if value(array) is not empty -->
<select name="{{ $variantName }}" id="{{ $variantName }}">
{{ range $v := $value }}
<option value="{{ $v }}">{{ $v | humanize }}</option>
{{ end }}
</select>
{{ end }}
{{ end }}
https://discourse.gohugo.io/t/anyway-to-dynamically-have-values-based-in-the-md-params/29906/3
My current html option selects look like this:
<select class="order form-control id="select-1">
<option value="{{ $resultItem1 }}" selected>{{ .item1 }}</option>
<option value="{{ $resultItem2 }}">{{ .item2 }}</option>
<option value="{{ $resultItem3 }}">{{ .item3 }}</option>
<option value="{{ $resultItem4 }}">{{ .item4 }}</option>
</select>
But I have functions that calculate the price for each option - here is the 1st of them:
{{ $resultItem1 := 0 }}
{{ with .Params.price1 }}
{{ $resultItem1 = printf "%.2f" (mul $.Params.margin . ) }}
{{ end }}
I would be very grateful if someone can tell me how I can range this function together with the option selects to calculate the respective price for each option and put the result into the select value="{{ }}".
Thank you!