How can we tell Hugo to treat everything as text and not to convert any other format?

---
title: ABC Product
productCode: 0276508
---

Inside md file, each product has some product code like “0276508”. But when it is building the pages in HTML for some pages it is converting as number like “2.9131983e+07” and for some pages it is as string like “0276508”. Used the below code to do this:

        {{ with .Params.productCode }}
        {{.}}
        {{ end }}

How can we tell Hugo to treat everything as text and not to convert any other format?

Never mind, got the solution:
{{ . | safeHTML}}

Ref: safeHTML | Hugo

If your product code looks like a number, it will treated as a number.

YAML front matter value Type
0276058 float64
276058 int
'0276058' string

You need to quote the value in front matter.

3 Likes

Awesome info. Got my code more clean. Thanks

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.