Is this possible? If I define $vars['sample_variable'] in template.php, and I try to insert this in a Contemplate template using print $sample_variable;, nothing prints. Is there another way I'm supposed to do this? Thanks.

Comments

jrglasgow’s picture

What type of variables are you trying to use in Contemplate? What is your final goal?

You definitely could do this if you included the template file first, i.e..

<?php
  include_once('/path/to/template.php');
?>

Also you can just create a node-nodetype-field.tpl.php, check out the documentation at 'admin/help/contemplate#disk-based'

akahn’s picture

I'm using $node variables that are part of the event module. I'm trying to take the event_start and event_end variables (e.g. 200803011800 aka March 1, 2008, 6pm) that the module supplies to create a variable that contains a human-readable date, (such as March 1, 2008), along with variables for the start and end time (such as 6pm). I am doing this in the contemplate fields at the moment, but I thought it might be more efficient to do this in template.php (so it wouldn't be done for every single node teaser in a view). Is this correct, or am I misguided?

Thanks for the tips on including template.php. I'll try going in this direction.

jrglasgow’s picture

on the template edit page you have the textarea where you add the template for teaser, body and rss. under each of these areas there is a dropdown link that will show you another text area with a list of the available variables, this link is titled: teaser variables, body variables and rss variables. These variables do include $node->event_start, $node->event_end, etc... of course this is only for events that have those variables.

It is possible to use $node->event_start in the body template and not in the teaser template.

akahn’s picture

Right, but if I want to make a custom variable, $date, a human-readable string based on $node->event_start, wouldn't I want to do this in template.php rather than right in Contemplate's teaser and body textareas?

jrglasgow’s picture

I guess I don't see any reason right now why you couldn't. I'm just saying it would be easy enough to do it in Contemplate with

  <?php
    $date = date('Y-m-d', $node->event-start);
  ?>