我必须根据 Drupal 中的页面名称将 JavaScript 代码的动态片段添加到多个页面。以下是片段的示例。我在代码片段中记录了数据将更改的位置。我的问题:在片段中,我将如何在有 HTML 注释字符的地方添加 php 变量?
JavaScript 代码:
<!--
Activity name of this tag: Kids Product Page **THIS DATA WILL CHANGE****
URL of the webpage where the tag is expected to be placed: http://www.mywebsite.com/thepage/goeshere.php **THIS DATA WILL CHANGE****
This tag must be placed between the <body> and </body> tags, as close as possible to the opening tag.
Creation Date: 09/05/2013 **THIS DATA WILL CHANGE****
-->
<script type="text/javascript">
var axel = Math.random() + "";
var a = axel * 10000000000000;
document.write('<iframe src="https://website.net/activityi;src=2584392;type=2013s677;cat=vitam148;ord=1;num=' + a + '?" width="1" height="1" frameborder="0" style="display:none"></iframe>'); **THIS DATA WILL CHANGE****
</script>
<noscript>
<iframe src="https://website.net/activityi;src=2584392;type=2013s677;cat=vitam148;ord=1;num=1?" width="1" height="1" frameborder="0" style="display:none"></iframe> **THIS DATA WILL CHANGE****
</noscript>
<!-- End of JS Code: Please do not remove -->
我有大约 20 个这段代码片段,我正在考虑创建一个复杂的数组,但是使用上面的注释字符,我不确定是否可以将 php 变量放在其中并且它仍然是注释。
大批:
$myData = array(
"kid_page" => array(
"page_name" => "Kids Product Page",
"page_url" => "http://www.mywebsite.com/thepage/goeshere.php",
"create_date" => "09/05/2013",
"docwrite" => '<iframe src="https://website.net/activityi;src=2584392;type=2013s677;cat=vitam148;ord=1;num=' + a + '?" width="1" height="1" frameborder="0" style="display:none"></iframe>',
"noscript" => '<iframe src="https://website.net/activityi;src=2584392;type=2013s677;cat=vitam148;ord=1;num=1?" width="1" height="1" frameborder="0" style="display:none"></iframe>'),
"adult_page" => array(
"page_name" => "Adult Product Page",
"page_url" => "http://www.mywebsite.com/thepage/goeshere.php",
"create_date" => "10/06/2013",
"docwrite" => '<iframe src="https://website.net/activityi;src=2584392;type=2013s677;cat=vitam148;ord=1;num=' + a + '?" width="1" height="1" frameborder="0" style="display:none"></iframe>',
"noscript" => '<iframe src="https://website.net/activityi;src=2584392;type=2013s677;cat=vitam148;ord=1;num=1?" width="1" height="1" frameborder="0" style="display:none"></iframe>'),