Question

Ok I have some custom Omniture code I need to add to a Drupal site. All is good as I have added the Javascript code to the themes template page. The code shows up on all the pages as expected but I have a couple of PHP variables that I need to print in the Javascript that are coming up blank.

<?php

    $omniture_event = "test this works as expected";

    $omniture =<<<OMNITURE
<script language="JavaScript"><!--

s.events="{$omniture_event}"
s.landing="{$omniture_landing}"

OMNITURE;

    echo $omniture;

?>

but $omniture_landing is set on the landing page only and it looks like the template page is being loaded first then the content of the page is being added. I can print the value to the screen and I see the Javascript in the footer as expected with the other PHP variable set, but when I try to set the variable on the landing page it comes up blank in the javascript.

Was it helpful?

Solution

You can edit your page.tpl.php template file. If the 'Landing page' is your front page, then you can do something a little easier and more consistent (if you end up changing the title).

if($is_front) { 
  $omniture_landing = 'Yeah we have landed!!!'; 
}

Or by node id:

if($node->nid == '1') { 
  $omniture_landing = 'Yeah we have landed!!!'; 
} 

Replacing 1 with whatever the node Id is of course

Also, check to see if you have a page-front.tpl.php If so, that file, page-front.tpl.php is the template that runs on the landing page instead of page.tpl.php and you can add your code to page-front.tpl.php or remove it if you don't need a separate template for the landing page.

OTHER TIPS

I ended up adding this to the template page (page.tpl.php) before the Omniture code

if($node->title == 'Landing Page Title') {
    $omniture_landing = 'Yeah we have landed!!!';
} else {
    $omniture_landing = '';
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top