Drupal 添加自定义 Omniture 代码,未设置 PHP 变量
好的,我有一些自定义 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以编辑 page.tpl.php 模板文件。如果“着陆页”是您的首页,那么您可以做一些更简单、更一致的事情(如果您最终更改标题)。
或者通过节点 id:
将 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).
Or by node id:
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.
我最终将其添加到模板页面 (page.tpl.php) 中的 Omniture 代码之前
I ended up adding this to the template page (page.tpl.php) before the Omniture code