Skip to content

Commit

Permalink
add liquid filter to format number
Browse files Browse the repository at this point in the history
  • Loading branch information
FuhuXia committed Dec 4, 2024
1 parent ee4744e commit b04697f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
8 changes: 8 additions & 0 deletions .eleventy.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,14 @@ module.exports = function (config) {
pathPrefix = process.env.BASEURL;
}

// add a liquid filter to separate numbers with commas
config.addLiquidFilter('toLocaleString', (string) => {
if (!isNaN(string)) {
string = parseFloat(string);
}
return string.toLocaleString('en', { useGrouping: true });
});

// Set image shortcodes
config.addLiquidShortcode('download', downloadShortCode);
config.addLiquidShortcode('image', imageShortcode);
Expand Down
4 changes: 2 additions & 2 deletions pages/metrics/metrics.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ <h6 class="usa-heading">Report Date: {{ metrics.end_date}} </h6>
<div class="grid-row grid-gap-lg {{cacheKey}}">
<div class="grid-col-12">
<h4>{{block.meta.title}}</h4>
<h3>{{ block.data[1] }}</h3>
<h3>{{ block.data[1] | toLocaleString }}</h3>
</div>
</div>
<div class="mt-3"></div>
Expand Down Expand Up @@ -92,7 +92,7 @@ <h4>{{block.meta.title}}</h4>
<td>{{column}}</td>
{%- endif -%}
{%- else -%}
<td>{{column}}</td>
<td align="right">{{column | toLocaleString}}</td>
{%- endif -%}
{%- endif -%}
{% endfor %}
Expand Down
2 changes: 1 addition & 1 deletion pages/metrics/metrics_per-org.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ <h4>{{block.meta.title}}</h4>
{%- endif -%}

{%- else -%}
<td>{{column}}</td>
<td align="right">{{column | toLocaleString}}</td>
{%- endif -%}
{%- endif -%}
{% endfor %}
Expand Down

0 comments on commit b04697f

Please sign in to comment.