I have a front-matter parameter, Params.img.ratio (indicating the image’s aspect ratio). I’m using forestry.io so the user chooses from a pre-defined list of options (5x4, 4x5, 16x9, and so on.). I need to break these numbers out into separate integers, in order to perform some math functions on them. (Please note that these images are hosted remotely and therefore imageConfig is not available to me.) The following (verbose, probably very misguided) code does yield the separate numbers, but as strings—not integers:
{{- $arWidth := index (first 1 (split .Params.img.ratio "x") ) 0 -}}
(For a 16x9 aspect ratio, this yields the string 16.)
{{- $arHeight := index (last 1 (split .Params.img.ratio "x") ) 0 -}}
(For a 16x9 aspect ratio, this yields the string 9.)
If, however, i attempt the following:
{{- $arWidth := int ( index (first 1 (split .Params.img.ratio "x") ) 0 ) -}}
{{- $arHeight := int ( index (last 1 (split .Params.img.ratio "x") ) 0 ) -}}
I receive the following error:
error calling int: unable to cast "" of type string to int
If anyone can see through this mess of code, and identify a better way, i’ll be in your debt.