I'm really struggling with how to get variables created in page.tpl.php and node.tpl.php in rendered content and blocks. I hope I'm just missing something simple.
Basically, I'm trying to have a unique ID number passed around the site. To do that (as far as I know) I need to add it to all the links, IE /?a_uid=123456.
I'm generating the random ID in success_preprocess_page (full code is below).
function success_preprocess_page(&$variables, $hook) {
//echo '<pre>'; print_r($variables); echo '</pre>';\
if (isset($_GET['utm_campaign']))
$adkey = $_GET['utm_campaign'];
elseif (isset($_POST['utm_campaign']))
$adkey = $_POST['utm_campaign'];
else
$adkey = NULL;
if (isset($_GET['a_uid']))
$a_uid = $_GET['a_uid'];
elseif (isset($_POST['a_uid']))
$a_uid = $_POST['a_uid'];
else
$a_uid = NULL;
if ($adkey != NULL)
{
$a_uid = "123456";
}
$variables['adkey'] = $adkey;
$variables['a_uid'] = $a_uid;
if(isset($variables['a_uid'])){
// add the flag to the node to say it's been set and there is only a single node to display
if(isset($variables["page"]["content"]["system_main"]["nodes"]) && count($variables["page"]["content"]["system_main"]["nodes"]) == 2){
$keys = array_keys($variables["page"]["content"]["system_main"]["nodes"]);
// Set a new variable called sidebar_first equal to true on the node.tpl level
$variables["page"]["content"]["system_main"]["nodes"][$keys[0]]['#node']->a_uid = $a_uid;
}
}
}
Any links that are in page.tpl.php, ex:
<a href="programs/?a_uid=<?php echo $a_uid; ?>">Programs</a>
Display the correct $a_uid variable result of 123456.
And if I try to echo $a_uid in node.tpl.php, ex:
<?php $a_uid = $node->a_uid; ?>
<?php //echo 'A_UID: '.$a_uid.'<br><br>'; ?>
Also displays 123456 fine.
But if I try anything like this in my content pages (even with them set as PHP Code Text Format, which correctly processes other PHP code), everything result is blank.
For instance, I currently have a content page that has this in it, trying to hit all the marks I can think of:
<?php echo $a_uid; ?>
<?php print $a_uid; ?>
<?php echo $node->a_uid; ?>
<?php echo $content->a_uid; ?>
<?php print $node->a_uid; ?>
<?php print $content->a_uid; ?>
<?php print ($page['a_uid']); ?>
<?php print ($node['a_uid']); ?>
Not a single one of those displays anything.
As far as I can tell it seems like the variable is just not getting passed to the content? I just don't understand why, or how to fix it.
I assume this is standard, but this is how my content is being called in node.tpl.php:
print render($content);
I am also having the same problems in my header and footer blocks. Those are being called from page.tpl.php as:
<?php print render($page['footer']); ?>
<?php print render($page['header_button']); ?>
Any help with this would be greatly appreciated. Thanks! Oh and 123456 is just a placeholder in here for my random unique ID generator code :)