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

View::renderString forces 'site' template mode and breaks plugins using it to render in the 'cp' context #5020

Closed
BenParizek opened this issue Sep 30, 2019 · 2 comments

Comments

@BenParizek
Copy link
Contributor

Description

We use the renderString method to render a template in the CP context in Sprout Reports Twig Template Reports. This lets us give users the ability to create settings using the Craft CP form macros and stay consistent with the Craft UI.

https://github.com/barrelstrength/craft-sprout-reports/blob/v1.2.7/src/datasources/CustomTwigTemplate.php#L127

In a recent release (v3.3.1 it appears) the renderString method now forces the site template mode and doesn't appear to give us a way to override it to set it to the CP template mode.

https://github.com/craftcms/cms/blob/3.3.6/src/web/View.php#L456

Steps to reproduce

  1. Create a custom Twig Template using Sprout Reports
  2. Use the {% import "_includes/forms" as forms %} in your settings template, which up until this point let you reference all the Craft form macros for your settings

Also see: https://github.com/barrelstrength/craft-sprout-reports/issues/63

Additional info

  • Craft version: 3.3.5
  • PHP version: 7.3
  • Database driver & version: postgres
  • Plugins & versions: Sprout Reports
@BenParizek
Copy link
Contributor Author

I haven't run into an issue here yet, and I feel I must be missing how these can be overridden if we wish to use them in the CP context, but it appears the renderObjectTemplate method has also has been updated in a similar way where template mode is being hard-coded to the site context:

https://github.com/craftcms/cms/blob/3.3.6/src/web/View.php#L511

@brandonkelly
Copy link
Member

Sorry about that, Ben. We started using the Site template mode when those methods are called so people could include their own site templates when they needed more space to work from, for things like entry URI formats, Commerce product SKU formats, etc. I didn’t realize that plugins were already including their own templates internally when calling that method.

I’ve added a new $templateMode argument to each of those methods for the next release, which you can start passing \craft\web\View::TEMPLATE_MODE_CP to, so your own plugin’s templates become available again.

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