protro Posted May 8, 2023 Share Posted May 8, 2023 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 More sharing options...
BitPoet Posted May 10, 2023 Share Posted May 10, 2023 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 More sharing options...
bernhard Posted May 10, 2023 Share Posted May 10, 2023 Hey @protro I've refactored RockFrontend so now you can use this: $latte = $rockfrontend->loadLatte(); It's in the latest DEV commit: https://github.com/baumrock/RockFrontend/commit/b0d1ac6b24bdf5085272d4c324db1b1f0e58fcd6 Does that work for you? Link to comment Share on other sites More sharing options...
gornycreative Posted August 11, 2023 Share Posted August 11, 2023 Nice I'm guessing this is how we could use the addFunction method also? Link to comment Share on other sites More sharing options...
bernhard Posted August 11, 2023 Share Posted August 11, 2023 Yeah, just check the docs here https://latte.nette.org/en/extending-latte#toc-functions and then instead of this $latte = new Latte\Engine; use this $latte = $rockfrontend->loadLatte(); Let me know if you come up with something useful. Never used that feature myself ? Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now