Jump to content

How to create a custom Latte filter ?


protro
 Share

Recommended Posts

Hi,

I am using @bernhard Rockfrontend with the Latte engine and wanted to create a custom latte filter called firstParagraph that grabs the first <p> from a field called body.

in _init.php I added the following:

// Include the Latte template engine library
require_once '../modules/RockFrontend/vendor/latte/latte/src/Latte/Engine.php';

// Create a new instance of the Latte engine
$latte = new \Latte\Engine;

// first paragraph summary filter
$latte->addFilter('firstParagraph', function ($s) {
    if (preg_match('/<p.*?>(.*?)<\/p>/', $s, $matches)) {
        return $matches[1];
    }
    return '';
});

But I get a Fatal Error

Trait "Latte\Strict" not found (line 18 of site/modules/RockFrontend/vendor/latte/latte/src/Latte/Engine.php)

Am I going about this the wrong way? Any help/feedback appreciated.

Link to comment
Share on other sites

Since Latte is a composer package, I'd assume you should require_once '../modules/RockFrontend/vendor/autoload.php' to make sure all dependencies of Latte\Engine are included as well.

Link to comment
Share on other sites

  • 3 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...