1

I have created a template file for my content type, but I don't know how to get form design in that page.

My content type name is wallpaper, and I created the page--node--add--wallpaper.tpl.php template file. How do I access the node title, or the node body, in the template file?

3 Answers 3

1

If you want to design the form then use hook_form_alter you will get form array. If you want to design the node page then user node--content_type.tpl.php.

1
  • I agree: I would never use a template file to alter the way a form is shown. hook_form_alter() can be implemented from a theme too, even if it is generally implemented by a module.
    – avpaderno
    Commented Dec 9, 2012 at 22:18
0

You need to create custom module

First, alter the original form

function YOURMODULENAME_form_alter(&$form, $form_state, $form_id) {
  if ($form_id == 'node_wallpaper_form') {
    $form['#theme'] = 'your_theme_name';
  }
}

function YOURMODULENAME_theme() {
  return array(
    'your_theme_name' => array(
      'variables' => array('form' => NULL),
      'template' => 'template_file_name',
    ),
  );
}

In the template_file_name.tpl.php put fields :

print drupal_render($form['field_name']);

//Drupal needs to render form_id, form token etc as well so also put this:
print drupal_render_children($form);
-1

node.tpl.php is the base node template.

If you look at the source code you can find all variables to render values in that .tpl file.

Available variables:

  • $title: the (sanitized) title of the node.
  • $content: An array of node items. Use render($content) to print them all, or print a subset such as render($content['field_example']). Use hide($content['field_example']) to temporarily suppress the printing of a given element.
  • $user_picture: The node author's picture from user-picture.tpl.php.
  • $date: Formatted creation date. Preprocess functions can reformat it by calling format_date() with the desired parameters on the $created variable.
  • $name: Themed username of node author output from theme_username().
  • $node_url: Direct URL of the current node.
  • $display_submitted: Whether submission information should be displayed.
  • $submitted: Submission information created from $name and $date during template_preprocess_node().
  • $classes: String of classes that can be used to style contextually through CSS. It can be manipulated through the variable $classes_array from preprocess functions. The default values can be one or more of the following:

    • node: The current template type; for example, "theming hook".
    • node-[type]: The current node type. For example, if the node is a "Blog entry" it would result in "node-blog". Note that the machine name will often be in a short form of the human readable label.
    • node-teaser: Nodes in teaser form.
    • node-preview: Nodes in preview mode.

    The following are controlled through the node publishing options.

    • node-promoted: Nodes promoted to the front page.
    • node-sticky: Nodes ordered above other non-sticky nodes in teaser listings.
    • node-unpublished: Unpublished nodes visible only to administrators.
  • $title_prefix (array): An array containing additional output populated by modules, intended to be displayed in front of the main title tag that appears in the template.
  • $title_suffix (array): An array containing additional output populated by modules, intended to be displayed after the main title tag that appears in the template.

Other variables:

  • $node: Full node object. Contains data that may not be safe.
  • $type: Node type; for example, story, page, blog, etc.
  • $comment_count: Number of comments attached to the node.
  • $uid: User ID of the node author.
  • $created: Time the node was published formatted in Unix timestamp.
  • $classes_array: Array of html class attribute values. It is flattened into a string within the variable $classes.
  • $zebra: Outputs either "even" or "odd". Useful for zebra striping in teaser listings.
  • $id: Position of the node. Increments each time it's output.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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