2

Coming from ruby and rails, I’ve been using slim (https://slim-lang.org) for years. It’s brevity and clarity have become the norm to me and writing and reading full html feels a bit exhausting.

I am wondering, is there a way to use slim with twig templates in Craft? Does anyone here use this combination? Would you be willing to share your setup?

Thank you!

1 Answer 1

1

To answer your question: I think you CAN, but it will not be easy.

Craft is built on top of the Yii framework. It lets you override things (settings, classes) in the config/app.php file that gets installed by default. So, you should be able to change the view renderer to anything you want:

<?php

return [
    'components' => [
        'view' => [
            'class' => 'craft\web\View',
            'renderers' => [
                'slim' => [
                    'class' => 'path\to\your\slim\ViewRenderer',
                ],
            ],
        ],
    ],
];

Of course, this would require a Yii ViewRenderer based on Slim, which I don't think is available (yet). You could build it yourself, based on the Twig ViewRenderer used by Craft.

The reason I would not do it, is that Craft has several Twig filters en functions that make your templating life easier. You'd have to create wrappers for those, to be able to use them. I don't think the added complexity of all this weighs up to the advantage of using Slim.

1
  • Thank you, seems like that I’ll continue working on the front-end in a separate project and copy the html to craft/twig templates.
    – aaandre
    Commented Nov 7, 2018 at 16:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.