where are the theme variables
gleble - March 1, 2008 - 19:02
Forgive my ignorance. I've never done this before. I'mtrying to make a new theme. I've made a page.tpl.php file
<?php
print $head_title
?>
<?php
print $head
?><?php
print $styles
?>The Home of Future Energy
<?php
if (is_array($primary_links)) :
?><?php
foreach ($primary_links as $link):
?><?php
print $link
?>
<?php
endforeach;
?><?php
print $closure;
?>This gives an error 'unexpected' $end line 39 which is a problem. My main problem is the variables eg $head $tyles. Where are they stored? How can I assign values?

Ummmmm
Firstly, I would base a new page.tpl.php on an existing one and add/subtract as required. As long as you keep opening and closing tags matched the $end problem should not happen.
Secondly, $head, $style et al are from an array called $vars['head'], $vars['style'] in the templating of Drupal. Have a look at the Garland template.php and you will see how you can modify or add variables:-
<?php
/**
* Override or insert PHPTemplate variables into the templates.
*/
function _phptemplate_variables($hook, $vars) {
if ($hook == 'page') {
if ($secondary = menu_secondary_local_tasks()) {
$output = '<span class="clear"></span>';
$output .= "<ul class=\"tabs secondary\">\n". $secondary ."</ul>\n";
$vars['tabs2'] = $output;
}
?>
www.purpleoar.co.nz/scryptik - Javascript editor with syntax error checking
www.purpleoar.co.nz - Web development, Drupal consultancy
bluemarine
Thanks , clarified nicely , getting there but stuck again. I want to use Bluemarine as a basis for the new page.tpl.php but there is no template.php.
You can
use any template.php file as a base. Just use what you need (i.e function _phptemplate_variables($hook, $vars)). Place it in your theme folder. Drupal will find it.
www.purpleoar.co.nz/scryptik - Javascript editor with syntax error checking
www.purpleoar.co.nz - Web development, Drupal consultancy
still stuck
$head and $style are not mentioned in template.php (garland) are they assumed. Where is the content for $style, $content. I'm sure I'm nearly there but it's not quite clicking.
The phptemplate.engine
generates all the things referred to in .tpl files. Template.php allows you to override anything. That example only tweaks secondary links for garland. You can do whatever you like using the array $vars[]. Once you "click" you will see how flexible it all is!
www.purpleoar.co.nz/scryptik - Javascript editor with syntax error checking
www.purpleoar.co.nz - Web development, Drupal consultancy
text
How does Drupal know where to look for the text and menus? My sandbox is at climatecalm.org but it still looks at climatecamp.org.uk.
This is a different
issue. All text and menus are stored in the db. You have a url problem. Did you shift the site from .org.uk to .org? There maybe a site url stored in settings.php and/or .htaccess. When you say "it still looks at", when exactly is this?
www.purpleoar.co.nz/scryptik - Javascript editor with syntax error checking
www.purpleoar.co.nz - Web development, Drupal consultancy
$content
Take a look at http://climatecalm.org/drupal/index.php The Drupal is hosted on climatecalm.org ,the text is from an instance of Drupal which used to be on climatecalm.org but is now on climatecalm.org.uk . Where in the databse is this text stored?. Is changing it in the databse the only way I can cange the text?. Where does the html file fit in?
Got it, I think
When I create content it creates an entry in the database. The html can be viewed by Firebug and is all nicely tagged so page.tpl.php can refer to it. I presume the css should also refer to the same html. Am I on the right track?
The reason I have the wrong text is that I am using the old database on the new installation.
If I create new variables eg $logo2 in template.php do I also have to create the variable in phptemplate.engine?
I want to put images in the header, do I have to give them new variables. It would be nice to edit the html I see in Firebug, is there a way of doing that?
Phew!
I have replied to the original post to unwind the mega indenting!
When you refer to the "html" do you mean content you have saved in a page/story node or the "view source" as delivered to the browser.?
Drupal is a dynamic system and each web page is constructed just before it is delivered to the browser (except if it is cached, but we won't worry about that now). The stuff you see with firebug is built up from content nodes, blocks, maybe images etc and the template file for that node type. CSS is included by the template file and/or various modules which have their own css. (There is an option to merge all the css into one file which saves lots of http requests and is a good performance improver.)
"The html can be viewed by Firebug and is all nicely tagged so page.tpl.php can refer to it. I presume the css should also refer to the same html. Am I on the right track?"
Page.tpl.php doesn't "refer" to the the html. It is an important part of how the html is created (a template!).
"The reason I have the wrong text is that I am using the old database on the new installation." Good, I am pleased that is cleared up!
"If I create new variables eg $logo2 in template.php do I also have to create the variable in phptemplate.engine?" NO, Never mess with core code! The template.php file is there exactly for your overrides.
"I want to put images in the header, do I have to give them new variables. It would be nice to edit the html I see in Firebug, is there a way of doing that?" You could give them new variables but maybe you could just alter the css for "header" in style.css in your theme. You can edit in firebug to temporarily see the effect. For permanent changes you need to go back to the cause, ie possibly content, css, template file(s), module options etc.
Hope that helps.
www.purpleoar.co.nz/scryptik - Javascript editor with syntax error checking
www.purpleoar.co.nz - Web development, Drupal consultancy
Thanks
That last posting clicked it. This a quick first properly working template
http://www.climatecalm.org/drupal/
oops
oops