rcrowe / TwigBridge

Give the power of Twig to Laravel
MIT License
895 stars 165 forks source link

Normalize path in compiler before sending it to twig->load() #439

Closed hsingh124 closed 2 months ago

hsingh124 commented 2 months ago

This PR addresses the issue https://github.com/rcrowe/TwigBridge/issues/438.

While compiling the twig templates, the view cache generated had the full path as the template name instead of the actual template name. This was a problem specially when using view composers. As we define view composers with template names, they were not being triggered due to the wrong name in cache files.

This fix adds code to normalize the path before sending it to twig->load() method, which expects the name of the template and not the path. Normalizing the path would convert it into the template name.

I'm not sure if this is the proper solution for this so please suggest alternatives if required.

Thanks!

hsingh124 commented 2 months ago

This would not work in all the cases, for example with themes. I think we need a way to pass in the template name instead of normalizing the path but I'm not exactly sure how to solve this problem.