I still don’t get it, bit confused try many variations but have no idea what you mean and what i am doing. the $floor will simply get the value but how can i define that value to change?
How i tell hugo to turn basement to 0 and ground to 2 etc?
I don’t understand what is the relations between those two code snippet, the first one are the front matter parameters, I’m confused by the second one, what is it? It would be helpful for others to answer your question if you could explain those parameters and their relations in detail.
Is there any reason not to declare floor as 5 in front matter? If you want to parse 2nd as 5, you’ve to transform the parameter in some rule, but I couldn’t provide futher info, since I don’t know why 2nd represents 5.
Yes, there are around 60,000+pages which will require frontmatter modification. So for me it will be way easier option to let json modify these values in the json template.
Can you please provide an example. What i realise the normal hugo fucntion that normally work are sometime not fucntioning the same way in the json template for me.
This gives me the idea of what you mean but still cant impliment.
i have front matter values like this
In the front matter floor which keeps values in the format "Basement", "Lower ground", "Ground", "Upper ground", "1st", "2nd", "3rd", "4th", "5th", "6th", "7th", "8th", "9th", "10th", "15th", "20th", "30th", "40th", "50+"
in json template i use
{{- with .Params -}}
{{- $.Scratch.Add "data" (dict "lastmod" .lastmod (dict "sqm" .details.sqm "floor" .details.floor)) -}}
{{- end -}}
this output json value "floor":"2nd" now instead of 2nd i would like to get single numeric value for 2nd “5” like this format
what i cannot figure out is in need to dict at what stage in the $.Scratch.Add or outside? at what stage i tell hugo that these values are coming from .details.floor?
Thank you for taking the time to help
Current error/issue
i try the above in multiple format this is the last one i tried
execute of template failed: template: _default/properties-for-sale.json.json:6:22: executing "_default/properties-for-sale.json.json" at <.details.floor>: can't evaluate field details in type page.Page
what i am doing wrong here? Is this the correct format to use?
2nd implementation
2nd format after better understanding your solution is this which also result in error:
execute of template failed: template: _default/properties-for-sale.json.json:35:22: executing "_default/properties-for-sale.json.json" at <index $lookuptable $floorvalue>: error calling index: index of type map[string]interface {} with args [<nil>] failed: value is nil; should be of type string
Since not all pages have the floor value i try the with indexelse but failed i will really appreciate if someone can show the light to solve this
I have duplicate values in json once at the begingin and second at the {{- $.Scratch.Add "data" (dict "lastmod" .lastmod (dict "sqm" .details.sqm "floor" $floor)) -}}
Secondly within the {{end}} tag i get proper values but outside i still get 2nd instead of 2
I wish there was a better way as these if else sound really stupid as the json template grows. wish there was a different method i can figure out to make it work but thats all i can do to make it work.