What happened?
Description
When using craft\fieldlayoutelements\Template in the admin panel ID like to use {% import "_includes/forms" as forms %}, but because it's rendered in SITE mode the CP templates are not loaded.
It works when I change vendor/craftcms/cms/src/fieldlayoutelements/Template.php:103 to TEMPLATE_MODE_CP, but I guess that could cause other issues.
Maybe there is a better way to accomplish this? My end-goal is to use the elementSelectField helper.
Alternatively template mode could be added as a config option:
new Template([
'template' => '_myplugin/test.twig',
'templateMode' => View::TEMPLATE_MODE_CP,
]),
Steps to reproduce
Event::on(
FieldLayout::class,
FieldLayout::EVENT_CREATE_FORM,
function (CreateFieldLayoutFormEvent $e) {
if ($e->element instanceof Course) {
$e->tabs[] = new FieldLayoutTab([
'name' => Craft::t('app', 'Test'),
'layout' => $e->sender,
'elements' => [
new Template([
'template' => '_myplugin/test.twig',
]),
],
]);
}
}
);
// test.twig
{% import "_includes/forms" as forms %}
Expected behavior
Should load the helpers.
Actual behavior
Unable to find the template “_includes/forms”
Craft CMS version
5.4.71
PHP version
8.2
Operating system and version
No response
Database type and version
No response
Image driver and version
No response
Installed plugins and versions
What happened?
Description
When using
craft\fieldlayoutelements\Templatein the admin panel ID like to use{% import "_includes/forms" as forms %}, but because it's rendered in SITE mode the CP templates are not loaded.It works when I change vendor/craftcms/cms/src/fieldlayoutelements/Template.php:103 to
TEMPLATE_MODE_CP, but I guess that could cause other issues.Maybe there is a better way to accomplish this? My end-goal is to use the
elementSelectFieldhelper.Alternatively template mode could be added as a config option:
Steps to reproduce
Expected behavior
Should load the helpers.
Actual behavior
Craft CMS version
5.4.71
PHP version
8.2
Operating system and version
No response
Database type and version
No response
Image driver and version
No response
Installed plugins and versions