简体   繁体   中英

Jekyll/Liquid way to print numbers with separator character?

I am printing large numbers in Jekyll (powered by Liquid), which by default does not perform any sort of formatting. I'd like to print integers with separator characters, eg render 12000 as 12,000 .

I've looked for a filtering option in Liquid that supports this to no avail. Do I need to write my own extension/filter and do this myself?

It does not look like there is a built-in filter to do this, and as "Virtua Creative" mentioned in a comment Shopify provides a JavaScript library for doing locale-specific number formatting. (Which makes sense, since the Jekyll code is generated with zero context of the environment where it will be read.)

So creating a plug-in is your best bet. However, it appears that a plug-in already exists to do this (and other basic types of filtering). See:

https://github.com/23maverick23/jekyll-humanize

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM