Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


how to print custom values in custom template in drupal

Posted on 2009-04-26
Medium Priority
Last Modified: 2012-05-06

HI i have created a content type call "mycontent"

it has 2 fields

Label: MyText , Name: mytext , type: Text
Label: MyImage , Name: myimage , type: Image

All good so far, I have create a custom theme and inside this i have included


my quesiton is, how do i get at the variables.

I wish to $mytext

I can render global variables ie $content
Question by:frosty1

Accepted Solution

webopius earned 2000 total points
ID: 24239175

You don't mention if you are using CCK or if you've written your own module for the custom content type.  If you've written your own module and all is working, the new field should be available to your node's tpl template as $mytext.

I guess it's not otherwise you wouldn't be writing here. So, areas to check:

1. Add   <?php print_r(get_defined_vars()); ?> to you node's tpl file for debugging just to see what variables are getting across. If you can, I'd recommend enabling the devel module and using   <?php krumo(get_defined_vars()); ?> instead as it gives a much better variables display.

2. Check your module's hook_load (<modulename>_load) function to make sure you are telling Drupal about your new variable, at the most basic level, it should look something like this:

function yourmodulename_load($node) {
      $newfields = array();
      $newfields['custom_field'] = 'Custom Field Value';      
      return $newfields;

(In the example above, this now makes $custom_field available to node.tpl)

3. If you want your new field to appear within the $content automatically, create a hook_view function like this:

function yourmodulename_view($node,$teaser = FALSE, $page = FALSE) {
       $node = node_prepare($node, $teaser);

      if (!$teaser) {

            $node->content['custom_field'] = array(
                  '#value' => 'Custom field value',
                  '#weight' => 1,
      return $node;

If none of this makes sense or isn't working, just let me know and I'll try to help.
Adam, Webopius.com


Author Comment

ID: 24369191
excellent response.much appreciated

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question