Allowing Smarty date_format modifier

For years I’ve use the date_format modifier in a smarty block like this:
“uploadDate”: “{$product.timestamp|date_format:”%Y-%m-%d"}T08:00:00+08:00",

Now, with v4.19.1 SP1, the output reports: “modifier ‘date_format’ not allowed by security setting

I added ‘date_format’ to the allowed modifiers in:
“app/lib/vendor/smarty/smarty/src/Security.php” like this:
public $allowed_modifiers = [‘date_format’];

But still the error message persists.
What am I missing?

You are using text smarty blocks in the block manager or blocks with template in files?

I’m using the block type HTML block with Smarty support (not the deprecated one).
The block is displayed in a Product Tab on the product page.
Therefor the block displays a product video under the tab on the product page.
Its full contents are:

	<p class="video video-container">
		<video controls="" width="100%"  poster="/video/poster/{$product.product_code}-video1.jpg">
		<source src="/video/{$product.product_code}-video1.mp4" type="video/mp4">
		</video>
         </p>
<script type="application/ld+json">
[
    {
      "@context": "https://schema.org",
      "@type": "VideoObject",
      "name": "{$product.product|strip_tags}",
      "description": "{$product.short_description|strip_tags}",
      "thumbnailUrl": [
        "{$product.main_pair.detailed.image_path}"
       ],
      "uploadDate": "{$product.timestamp|date_format:"%Y-%m-%d"}T08:00:00+08:00",
      "contentUrl": "https://www.***.com/video/{$product.product_code}-video1.mp4"
    }
]
</script>

The date_format modifier is for the required Google format.

Yes, “HTML block with Smarty support” now has limitations with modifiers, try to change this block to tpl file.

What I want to do is to add the modifier ‘date_format’ to the Smarty allowed modifiers array.
I did this in the Security.php script for Smarty (as shown above) and it is still not allowed/throws the error.

Try to extend the following schema

app/schemas/block_manager/smarty_allowed_functions.php

3 Likes

Thank you!
I wasn’t aware of this schema and it’s exactly what I was looking for.

2 Likes