1

I am still relatively new to Craft CMS. I am trying to make a custom field plugin for Craft 3 but I am struggling to understand why I can't render my form template.

The fieldtype should render a map with markers in an entry, depending on which checkbox is clicked before map creation.

I have the following code in my Field.php file:

public function getInputHtml($value, ElementInterface $element = null): string
{ 
...

Craft::$app->getView()->setTemplateMode(View::TEMPLATE_MODE_SITE);
$input = Craft::$app->getView()->renderTemplate('locations-map/_includes/forms/mapElement', $variables);
}

And I get the following error: enter image description here

This is the result from all the vague(in my opinion) information in the internet about making custom field types in Craft 3 CMS.

If you have an idea how to access this template or just any information about custom fields, please feel free to share. (Yes, I have read the official documentation)

1

Where are you storing your mapElement template? - Unless it is stored in the same folder as the templates for the front end of your site, then

Craft::$app->getView()->setTemplateMode(View::TEMPLATE_MODE_SITE);

is telling craft to look in the wrong place.

If you've got it stored in your plugin directory, then you don't need to change the template mode at all, as per : https://docs.craftcms.com/v3/extend/updating-plugins.html#rendering-templates

  • Yes, I've initially tried without the Template mode but I still can't find the template. I can't even track where it's looking for the template. For now what works for me in the getInputHTML is to return HTML input without redirecting. – ves Aug 13 at 7:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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