giorgiopogliani / twig-components

Twig components inspired from blade components
MIT License
71 stars 16 forks source link

Add support for OctoberCMS / WinterCMS #27

Closed marcomessa closed 1 month ago

marcomessa commented 2 months ago

Hello there, thank you for your great work. In order to use this extension with OctoberCMS / WinterCMS, I need to update how the component path is generated. This CMS load twig always with .htm extension and using a hint path style.

Es.

mynamespace
|__ myplugin
    |__views
        |__ components
             |__ button.htm

can be references as "mynamespace.myplugin::components.button". Not using this syntax cause the CMS's custom twig loader to fail. With this PR I add a basicu support for using hint paths, using this syntax:

 Configuration::make($twig)
                ->setNeedsHintPath(true)
                ->setTemplatesPath('mynamespace.myplugin::components')
                ->useCustomTags()
                ->setup();

Let me know if you like the idea and if you want to change something! Cheers!

giorgiopogliani commented 2 months ago

@marcomessa what about adding a second param to the setTemplatesPath like:

 Configuration::make($twig)
                ->setTemplatesPath('mynamespace.myplugin::components', hint: true) // default false
                ->useCustomTags()
                ->setup();
giorgiopogliani commented 2 months ago

Also, could you add a small test?

marcomessa commented 2 months ago

Sure! I'll update this pr as it's done!

marcomessa commented 2 months ago

Hello @giorgiopogliani, are the modifications and tests ok? Do I need to edit something else?