Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP TwigRenderer Error when adding custom Twig extension via alter-twig.php #1495

Open
elvismdev opened this issue Jun 10, 2023 · 1 comment

Comments

@elvismdev
Copy link

I am using Pattern Lab Node v6.0.1 on Ubuntu Linux, with Node v18.14.0 and using the twig-php pattern engine.

I'm having trouble adding a custom Twig extension via alter-twig.php. Essentially after adding my extension and running yarn start it keep breaking into this error:

PHP TwigRenderer Error: The response callback is expected to resolve with an object implementing Psr\Http\Message\ResponseInterface, but rejected with "Error" instead

Not sure if I'm missing something else around my setup to add this extension to the Twig environment, or if this is an actual bug. Docs haven't helped much.

I'm adding screenshots for greater visual reference of my current setup and dependencies.

Expected Behavior

Register Twig custom extension and start Pattern Lab as expected without breaking into TwigRenderer errors.

Actual Behavior

After adding the extension in alter-twig.php and running yarn start to let Pattern Lab build and start the server, it keep breaking into this PHP TwigRenderer Error.

Steps to Reproduce

2023-06-09_19-38

2023-06-09_19-36

2023-06-09_19-38_1

2023-06-09_19-37

2023-06-09_20-13

@hadl
Copy link
Contributor

hadl commented Jul 31, 2023

Rendering Twig is handled by @basalt/twig-renderer which comes with a separate vendor directory and is not providing twig-extras (https://github.com/knapsack-cloud/twig-renderer/blob/master/composer.json).

Using your own composer.json and vendor directory in the Patternlab-directory is not working.

Best is to "mock" your e.g. custom project Twig functions inside the alter-twig.php to be able to use the same template in Patternlab and your project "live rendering".

I am using directories and simple files for that to keep it more organized.
Example for a trans filter: https://gist.github.com/hadl/82ba9b1a8088570163e813a594cfa5d0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants