how to print custom values in custom template in drupal

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
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
frosty1Author Commented:
excellent response.much appreciated
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.