how to print custom values in custom template in drupal

Posted on 2009-04-26
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
    LVL 4

    Accepted Solution


    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.


    Author Comment

    excellent response.much appreciated

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit ( and similar technologies have enjoyed wide adoption, making it possib…
    Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
    The viewer will learn how to dynamically set the form action using jQuery.
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

    737 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

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now