within my page.tpl.php I have the following code which makes some trouble in the backend. Therefore I want to solve it the better way, with preprocess functions.
if (!path_is_admin(current_path())) {
$pathArray = explode('/', current_path());
if (!empty($pathArray)) {
$path_to_node = url("node/".$pathArray[1]);
$img = '<img src="'.$theme_path.'/images/default.png" alt="Default" />';
if (!empty($path_to_node)) {
$menuChildArray = explode('/', $path_to_node);
if (!empty($menuChildArray[2])) {
$menuParent = $menuChildArray[2];
switch($menuParent) {
case "one":
$img = '<img src="'.$theme_path.'/images/one.png" alt="Pic tne!" />';
break;
case "two":
default:
$img = '<img src="'.$theme_path.'/images/two.png" alt="Pic two!" />';
break;
}
}
print $img;
}
}
}
But how can I realize this? To try it, I did the following:
I added a template.php to the Theme folder and added:
function set2015_preprocess_page(&$variables) {
$variables['set2015_pics'] = 'test';
}
Within page.tpl.php I then did:
<?php
print $set2015_pics;
But nothing is getting printed... What am I doing wrong here?
Thank you!
Presuming that set2015 is the name of your theme everything looks good so clearing cache with drush or at config/development/performance should make the variable show up. If set2015 is not the name of your theme then rename the function set2015_preprocess_page to YOURTHEME_preprocess_page
Debug it. Add some echo "I'm here";
above first if
, then bellow it, then after second if
and so on...to see what is executed and what's not. Try localizing the problem.