ethercreative / seo

SEO utilities including a unique field type, sitemap & redirect manager
MIT License
276 stars 95 forks source link

Unable to find the template “seo/_seo/fieldtype”. #459

Closed gleerman closed 1 year ago

gleerman commented 1 year ago

Description

For some unexplainable reason, I am getting the Twig Template Loading Error Unable to find the template “seo/_seo/fieldtype”. I was able to set up the SEO plugin correctly, complete its settings via the sidebar, and create a field of type SEO and add that field to an (existing) entry type. However, when I open an entry that of that entry type (or create a new one), the error occurs image

I have been deepdiving in the code and been tweaking some things here and there to see what is going on. The error originates from the getInputHtml function in SeoField.php file. The seo/_seo/fieldtype template cannot be rendered.

What I did to see what would happen: in the getSettingsHtml function of the same file, I changed the template from seo/_seo/settings to seo/_seo/fieldtype and then navigated to the field settings in the Craft CP. I was baffled to see that the errors there were Twig Runtime Errors (Variable "id" does not exist) which proved that the template indeed was found and merely couldn't be rendered due to wrong parameters (hence expected behaviour after this debug change).

So apparently the CP can find the seo/_seo/fieldtype template when in a setting path, but not in an entry. To further know why, my understanding of the Craft rendering mechanism is too limited. So I am reaching out for help.

After some more debugging, I found that the $roots object in which the template resolver is looking, is empty when the error occurs, but has values when all is going fine. These values also include the paths towards the templates of Redactor, Typed Link Fields, and other plugins.

Any input is appreciated, as I am stuck to set up SEO properly on my Craft website. Thanks a lot!

Steps to reproduce

  1. Add and setup the SEO plugin
  2. Set up a field of type SEO
  3. Add the field to an entry type
  4. Edit an entry of that type -> Twig Template Loading Error Unable to find the template “seo/_seo/fieldtype”.

Additional info

gleerman commented 1 year ago

Okay I seem to have fixed this by changing the field type to Plain text, saving it, and then to SEO again.

alexjcollins commented 1 year ago

Thanks for the writeup and update @gleerman. Do you think we can put this error down to something not executing properly/fully when the filed was first created, or do you feel its' something that warrants further investigation on our side?

gleerman commented 1 year ago

@alexjcollins I don't know what went wrong, honestly. The setup options in the CP are limited, so I don't think I misconfigured something. Either it was indeed a bug under the hood upon the SEO field creation, or it might be something more fundamental – even in Craft CMS – geven that this $roots object was empty and not showing any path towards my installed plugins. Glad I got it solved, and the trick to change types might be helpful to others, but the root cause of the issue remains unknown.

alexjcollins commented 1 year ago

I've definitely had issues in the past where a custom field doesn't get created properly - I wasn't sure at the time if it was Craft or the plugin. I'll close this for now, and at least the 'fix' is here if someone has a similar issue. Thanks again.