I'm attempting to theme a node add form for my new slide show content type in D8 using an example for D7 that I found here, but I'm not having much luck.

I've made and enabled a module named modulename, and have this in modulename.module:

function modulename_theme($existing, $type, $theme, $path) {
  return array(
    'slide_show_node_form' => array(
      'render element' => 'form',
      'template' => 'slide-show-node-form'

and in modulename/templates/slide-show-node-form.html.twig I have this:

<div class="layout-node-form clearfix">
  <div class="layout-region layout-region-node-main">
    {{ form|without('advanced', 'actions') }}
  <div class="layout-region layout-region-node-secondary">
    {{ form.advanced }}
  <div class="layout-region layout-region-node-footer">
    {{ form.actions }}

But, no luck on getting test to print out on the node add page. Any ideas on what I'm missing?

closed as too broad by kiamlaluno Aug 11 at 10:00

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.


Try this:

 * Implements hook_form_FORM_ID_alter().
function mymodule_form_node_form_alter(array &$form, array &$form_state, $form_id) {
  $form['#theme'] = 'slide_show_node_form';
  • Using jshow_forms_form_slide_show_node_form_alter I was able to get dpm to output something, but using $form['#theme'] = 'slide_show_node_form'; within it yielded no results. – Samsquanch Jun 13 '14 at 13:26
  • Try hook_form_alter() instead. Sometimes even I don't pick proper form id so I always use this to be sure I get it right and then use the proper form id in the hook_form_FORM_ID_alter for better DX instead of having just one hook_form_alter. – user21641 Jun 13 '14 at 15:24
  • I actually pulled the form_id from hook_form_alter (dpm($form_id) on the node create page) and double checked that dpm() was working on the node create page after I switched to hook_form_FORM_ID_alter, but it still didn't seem to be picking up my theme. – Samsquanch Jun 13 '14 at 15:27
  • It may be stupid but just ot be sure, check if you are referencing the $form array in the function/hook arguments. – user21641 Jun 13 '14 at 16:23
  • And of course always clear the cache :) – user21641 Jun 13 '14 at 16:25

Try adding something like the following to the top of your modulename/templates/slide-show-node-form.html.twig

 * @file
 * Override for Slide Show Node Form 'form' element.
 * Available variables
 * - attributes: A list of HTML attributes for the wrapper element.
 * - children: The child elements of the form.
 * @see template_preprocess_form()
 * @ingroup themeable

(based on the default located at /core/modules/system/templates/form.html.twig) and the suggestions for Drupal Twig conversion instructions

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