views:

62

answers:

2

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.

+2  A: 

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.

nowarninglabel
Thanks I tried this and didn't get it to work, +1 though
Phill Pafford
using you solution from your comment below
Phill Pafford
+1  A: 

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 = '';
}
Phill Pafford
I see, 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!!!';}...
nowarninglabel
Or at the least I would doif($node->nid == '1') { $omniture_landing = 'Yeah we have landed!!!';}Replacing 1 with whatever the node Id is of course. Anyways, glad you figured it out and thanks for the upvote.
nowarninglabel
Not a bad idea to use the node id instead of a string, thnx. Please edit your answer to include this option so I can select it as the accepted answer
Phill Pafford
Thanks, edited :)
nowarninglabel