By wrburgess on
Is there a definitive guide for how to theme an Add Node Form for a Custom Content Type in Drupal 7? I've read a number of posts regarding this issue, but none of the solutions seem to work.
Here are the links I've tried to follow thus far (without anything working):
Questions regarding theming Drupal 7 edit node forms
What I've tried, none seem to work
- http://drupal.org/node/1006404#comment-3866658
- http://drupal.org/node/1006404#comment-3892798
- http://drupal.org/node/983864#comment-3939860
- I've refreshed the cache and theme registry about a million times
For the sake of simplicity, I'll say the name of the custom content type is "event" and the name of the theme is "customtheme."
Thus, I'm trying to theme the /node/add/event page
If I can figure this out, I'll be glad to document the entire process for future Drupal developers. However, I'm pretty lost at the moment.
Comments
HTH
Overriding node edit DOES work using template.php
Posted by .zLaW on January 14, 2011 at 7:49pm new
Howdy,
I made a custom content type containing two taxonomy term reference fields with checkboxes. My goal was to theme the two checkbox fields to show up beside each other using float: left divs. The content type (machine name) is "elisa" and the two fields are "field_elisa_type" and "field_elisa_var".
I'm using a subtheme of Adaptive Theme for D7 called lab_book, if it matters. Just a stock copy of the starter subtheme, actually.
I added the following to my template.php file:
function lab_book_theme() {
return array(
'elisa_node_form' => array(
'arguments' => array('form' => NULL),
'template' => 'elisa',
'render element' => 'form',
),
);
}
Then I made a "elisa.tpl.php" file, sitting in the root folder of my subtheme that contains the following code:
print drupal_render($form['title']);print drupal_render($form['body']);print drupal_render_children($form['field_elisa_type']);print drupal_render_children($form['field_elisa_var']);print drupal_render_children($form);Works as wished for, rendering titel/body/floated checkboxes and finally the rest of the form and buttons.
Notice that the title and body fields are printed with "drupal_render" and the other fields (including the rest of the form at the end) are printed with "drupal_render_children". Why? I am not sure but it only works this way. Any insights would be appreciated.
Hope that this helps someone.
.zLaW
Yep. I gave that a try. It
Yep. I gave that a try. It didn't work for me. There was no effect on the page at all. Not even an error.
Hmmm...
Did you try doing;
That should dump all of your form array/object so you can see what is set and what values are assigned.
Doesn`t work for me too
Same for me, can`t get to see anything from the custom tpl, seems like it is being ignored...
tried to "print", "echo", "die"... nothing has any effect.
Drupal 7.9
If you want to make it work in D7 you must absolutely create a module, you can't use template.php (wasn't working for me tough).
YOUR_MODULE.module:
sites/all/themes/*YOUR_THEME*/templates/forms/*CONTENT_TYPE_NAME*--node-form.tpl.php:
I hope it will help someone else!
Credits goes to the user "Csabbencs": http://drupal.org/node/983864#comment-3939860
Hi Sir! But what if I wanna
Hi Sir!
But what if I wanna create tpl.php file for more than one content type form?
I cannot grasp the idea of structure...
And I can not understand this piece of code, sorry
About that comment
About that piece of code:
'template' => '*CONTENT_TYPE_NAME*--node-form', //name of your template file, it can be anythingIt means to replace "*CONTENT_TYPE_NAME*" with the machine name of your content type, so if your content type was 'blog', you'd say:
'template' => 'blog--node-form',The comment "
//name of your template file, it can be anything" just means that because the template file isn't being autodetected based on a naming convention, you could instead call your template file something else — for instance,custom-blog-form-template.tpl.php(I'm not endorsing this choice, just explaining) — in which case you'd need to here write:'template' => 'custom-blog-form-template',Basically, that piece of the line should be replaced with your template file's filename, minus the '.tpl.php' extension.
Theming the node/add page of custom content?
Did you ever figure it out and did you ever document it? I've read some posts etc but a lot of it is suggestions and it's hard to know whether they are correct or not?
Thanks in anticipation.
Try reading this
https://drupal.org/node/1124036
It took me a couple of hours to figure it out.