Drupal 添加自定义 Omniture 代码,未设置 PHP 变量

发布于 2024-09-27 19:11:51 字数 553 浏览 3 评论 0原文

好的,我有一些自定义 Omniture 代码需要添加到 Drupal 站点。一切都很好,因为我已将 Javascript 代码添加到主题模板页面中。代码按预期显示在所有页面上,但我需要在 Javascript 中打印几个 PHP 变量,这些变量显示为空白。

<?php

    $omniture_event = "test this works as expected";

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

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

OMNITURE;

    echo $omniture;

?>

但 $omniture_landing 仅在登陆页面上设置,看起来首先加载模板页面,然后添加页面内容。我可以将值打印到屏幕上,并且按照其他 PHP 变量集的预期,在页脚中看到 Javascript,但是当我尝试在登陆页面上设置变量时,它在 javascript 中显示为空白。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

信愁 2024-10-04 19:11:51

您可以编辑 page.tpl.php 模板文件。如果“着陆页”是您的首页,那么您可以做一些更简单、更一致的事情(如果您最终更改标题)。

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

或者通过节点 id:

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

将 1 替换为节点 ID 当然

也可以,检查是否有 page-front.tpl.php 如果有,则该文件 page-front.tpl.php 是在其上运行的模板登录页面而不是 page.tpl.php,您可以将代码添加到 page-front.tpl.php,或者如果您不需要登录页面的单独模板,则将其删除。

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.

苦妄 2024-10-04 19:11:51

我最终将其添加到模板页面 (page.tpl.php) 中的 Omniture 代码之前

if($node->title == 'Landing Page Title') {
    $omniture_landing = 'Yeah we have landed!!!';
} else {
    $omniture_landing = '';
}

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 = '';
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文