Convert shortcode parameters to actionable floats

#1

I’m trying to do some math from a nested shortcode. My code looks like

{{ with .Parent }}
{{ $blocks := (div 12 (.Get "columns")) }}
<div class = 'column col-lg-{{ with $blocks }}{{ . }}{{ else }}12{{ end }}'>
  {{ .Inner }}
</div>
{{ end }}

The columns value would be from the parent shortcode. My code fails so far because the input value of columns is a string. I would like to convert it into a float that would be work with the division operation.

0 Likes

#2

You can use float: https://gohugo.io/functions/float/ or int: https://gohugo.io/functions/int/

0 Likes

#3

Thank you @pointyfar

0 Likes