Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By Draven_Caine on
OK maybe someone can help me with this.
I have the node edit template working (one node edit template for all node types) by looking at the seven theme. What I am looking to do though is have a separate node edit template per content type, Luke what you can do with the node view template system. Is this possible and if so can someone help me out a bit?
Comments
You can turn on debug to look
You can turn on debug to look at theme suggestions output.
Open /sites/default/services.yml
and change:
Clear the cache and when you view a node page, you should see some theme suggestions.
When you add a new template, don't forget to clear the cache each time so it will appear.
Also, take a look at Drupal 8 template naming conventions: https://www.drupal.org/node/2354645
-----------------------------------------------------------------
We build engaging websites and intuitive designs that will benefit your business.
Duvien
Its for the node edit, not
Its for the node edit, not the node view.
There isn't a services file,
There isn't a services file, only default.services. where should the debug info print? I don't see it on the view or edit page.
Sorry yes, default.services
Sorry yes, default.services.yml on line 58 (see: https://www.drupal.org/node/1906392)
You create a template file and place it in your theme folder to override the default template. Perhaps, i misunderstood what you are trying to do? are trying to create a new content type so you can have a different edit node?
-----------------------------------------------------------------
We build engaging websites and intuitive designs that will benefit your business.
Duvien
No the template used for the
No the template used for the node edit form (content/3/edit for example) right now I had to add a function to my .theme file for it to use node-edit-form.HTML.twig. that file controls all node edit forms, I want a separate template file per content type on the edit form. So "plants page" content type would use a different template file for it's edit form than "campgrounds" content type.
I have the template working,
I have the template working, (look at the theme suggestion in bartik). Now I am trying to get individual form fields to print. {{ children }} prints all form fields. Any help?
How to use different node edit form templates for node types
This feels hacky, but it's the best I can come up with. First add this code to your admin .theme file (likely a sub-theme of Seven):
Next, create twig templates in your theme's template directory in the form of node-edit-form--NODE-TYPE-SEPARATED-WITH-DASHES.html.twig.
Learn virtually any aspect of Drupal on BuildAModule, where I've recorded over 2200 video tutorials.
Target a form mode?
The hook_theme_suggestions_alter works great. Thanks for that. Could it be used to target a form mode?
Not working
hook_theme_suggestions_alter gets called a lot on a node edit page, but 'node_edit_form' is not one of the $hook values. HTML, Page, Regions, Blocks and Fields are all listed, but not the node form itself. I can't find anything else there to hook on to add the node edit template suggestion to.
Edit: turns out my problem is that I want to display node edit forms using the front-end theme. I'm doing this by setting _admin_route to false using an alterRoutes function in a custom RouteSubscriber class in my module. This works a treat, but it seems to prevent hook_theme_suggestions_alter from being called.
To fix this issue, I had to use a hook_form_alter in my module to catch all the node forms and set:
$form['#theme'] = ['node_edit_form'];
complete steps here
I created a step by step guide here https://drupal.stackexchange.com/a/308548/69482