- I have a shortcode : It process a CSV file and he tracks column sums for each value of a certain critera : (myCritera; item 1; Item 2; item N).
- myCritera unique values are : ValueA, ValueB, … ValueZ
- Informations about CSV file and column number to be processed are all in a front matter .md. And number of column is variable.
- Finally I get a map for column Item 1 :
item 1:[valueA:sumA ValueB:sumB ...]
. It works fine.
But to achieve that I use $.Scratch.SetInMap "myTempMap"
to store the temporay map.
And reuse this myTempMap on my range iteration over each column Item N
Problem is that it store the map and not the maps’s value. So each iteration change the maps I previously stored. And finaly I get a nice map but with the same values stored !!
I tried to use a dict but i can’t add some value to a dict without using Scratch.SetInMap => catch 22.
I guess I miss something obvious, … but what ??
EDIT : And as my number of values is unknown, I can’t use prenamed maps (which would make my code work)
In my front matter I have [11, 12, 17] for example = > $listeColStats
{{- range $k, $codeStatTemp:= $listeColStats -}}
{{- range $listeCodes1Categ -}}
{{- $.Scratch.SetInMap "mapSommeCateg_1total_Temp" . 0.0 -}}
{{- end -}}
{{- $csv := getCSV ";" ($.Scratch.Get "csvURL") -}}
{{- range $i, $ligneTemp := $csv -}}
{{- if gt $i 0 -}}
{{- $codeCategTemp := (index $ligneTemp $numcol_categ) -}}
{{- $val_FR_str := index $ligneTemp $codeStatTemp -}}
{{- $val_US_str := replaceRE "," "." $val_FR_str -}}
{{- $val2add := float (lang.NumFmt 2 $val_US_str "- .") -}}
{{- $valOrigineCol := (index ($.Scratch.Get "mapSommeCateg_1total_Temp") $codeCategTemp) -}}
{{- $valResult := add $val2add $valOrigineCol -}}
{{- $.Scratch.SetInMap "mapSommeCateg_1total_Temp" $codeCategTemp $valResult -}}
{{- else -}}
{{- end -}} <!-- Fin de test en-tête -->
{{- end -}} <!-- Fin de range CSV -->
<!-- HERE IS THE VALUE I WANT TO KEEP AFTER EACH ITERATION -->
{{ $_ := ($.Scratch.Get "mapSommeCateg_1total_Temp") }}
{{- $.Scratch.SetInMap "mapStatTotaux" (string $codeStatTemp) $_ -}}
{{- end -}}
`
``