Blog Sections Open

Formatting Price Output with parseTplChunk in Evolution CMS

If a chunk only needs a clean price string, it is often easier to prepare the value first than to keep stacking modifiers in the template.

The donor behind this post solved a very practical problem: prices stored in resources or TVs were reaching the chunk in an unformatted state, while the final output needed a human-readable format such as 10 000.

Simple formatter example

<?php
if ($output) {
    $price = str_replace(" ", "", $output);
    $price = (int)$price;
    $result = number_format($price, 0, ',', ' ');
    return $result;
}
?>

parseTplChunk context

The original article also showed a custom loop where resource data and TV values were prepared before being passed into parseTplChunk. That approach is still valuable: if the template only needs clean final values, prepare them in PHP and keep the chunk focused on markup.

Why this is preferable

  • chunks stay simpler
  • number formatting becomes consistent
  • logic can be reused for more than one output template

This is a small pattern, but it is a good example of a broader Evo rule: move repeatable data shaping out of the template when the template only needs presentation.

Newer post

Showing a Video Block in Ditto Only When the TV Has a YouTube ID

How to conditionally render a video block in Ditto listings when a video TV may be empty and the project needs safe fallback markup.

Older post

Building a “Recently Viewed Products” Snippet in Evolution CMS

How to track recently viewed products with session data in Evolution CMS and render a simple block of viewed items on product pages.