This section of the FreeMarker template is responsible for processing and formatting item dimensions (length, width, height) to three decimal places.
The input string: 5″ x 4″ x 2″
- Assign Original String: The dimensions of the item are stored in the
dimensionsvariable.
<#assign dimensions = itemLineDetails.dimensions />
- Remove Double Quotes: To facilitate easier processing, double quotes are removed from the dimensions string using the
replacefunction.
<#assign dimensions_cleaned = dimensions?replace(""", "") />
- Split Dimensions: The cleaned dimensions string is split into individual parts using the
' x 'delimiter.
<#assign dimension_parts = dimensions_cleaned?split(" x ") />
- Initialize Formatted String: A variable
formatted_dimensionsis initialized to store the formatted result.
<#assign formatted_dimensions = "" />
- Loop Through Parts: The code loops through each dimension part, converting it to a number and formatting it to three decimal places.
<#list dimension_parts as part>
<#assign formatted_part = (part?number)?string("0.000") />
- Concatenate Formatted Parts: The formatted parts are concatenated with the appropriate units (
" x "or"), depending on whether it’s the last part or not.
<#if part_has_next>
<#assign formatted_dimensions += formatted_part + "" x " />
<#else>
<#assign formatted_dimensions += formatted_part + """ />
</#if>
</#list>
- Output the Result: Finally, the formatted dimensions are output.
${formatted_dimensions}