我的PHP非常生疏,自从我做了PHP以来,已经有好几年了,而且我有一点脑屁。我正在尝试创建PHP代码,以便根据您所在的页面显示不同的链接(使其成为一个人根据他们所在的页面被带到不同的“联系我们”页面。)
文件fieldgroup-simple-group_product_header.tpl通过根据您所在的页面显示不同的社交媒体链接来执行类似的操作。理想情况下,我想使用相同的变量来确定要在此PHP文件中显示的社交媒体链接。如何从不同的文件中调用变量?我尝试使用include语句但是当我尝试打印变量以确保它工作时,没有显示任何内容。
我想我可以在文件fieldgroup-simple-group_product_header.tpl中调用标识页面类型的变量,并使用它来确定要显示的链接类型。
谢谢,
道格
以下是两个文件:
FIELDGROUP-简单group_product_header.tpl
<?php
// $Id: fieldgroup-simple.tpl.php,v 1.1.2.1 2009/02/28 23:56:17 yched Exp $
/**
* @file fieldgroup-simple.tpl.php
* Default theme implementation to display the a 'simple-styled' fieldgroup.
*
* Available variables:
* - $group_name - The group name
* - $group_name_css - The css-compatible group name.
* - $label - The group label
* - $description - The group description
* - $content - The group content
*
* @see template_preprocess_fieldgroup_simple()
*/
?><? //print_r( get_defined_vars()); die();?>
<?php
if ($content) :
$content_div_id = $group_name;
$holderId = $group_name . "_holder";
$show_div_class = "show_link_holder";
$hider_link_class = "group_hide_link";
$show_link_class = "group_show_link";
$show_link_id = $group_name ."_show_link";
$show_link_text = $label;
$href = "#" . $content_div_id;
//die( $show_link_text );
?>
<div class="fieldgroup <?php print $group_name_css; ?>" id="<?=$holderId ?>" title=" <?=$label ?>">
<div class="group_content" id="<?=$content_div_id ?>">
<?php print $content; ?>
<div class="clear"></div>
</div><!--close #<?=$content_div_id ?>-->
</div><!--close #<?=$holderId ?>-->
<?php endif; ?>
和contact-us.php文件代码:
<?
//this is the location of the product header file that defines the variable that determines the content type
include '/sites/all/themes/tekzennew/fieldgroup-simple-group_product_header.tpl';
function build_info_form($node)
{
$node_url = $node->path;
$is_canine = strcasecmp($node_url, CANINE_STUDY_URL) == 0;
$img_src = $is_canine ? "/sites/default/files/case-study-orange.gif" : "/sites/default/files/info-orange.gif";
?>
<div class="request-info-holder system-sidebar-container">
<div id="request-info-header" class="system-sidebar-header">
<span class="request-form-title">Contact Us</span>
</div>
<div id="request-info-content" class="system-sidebar-content">
<span class="phone">800.248.3669 | 617.464.4500</span>
<?php
if ($a > $b) {
echo "a is bigger than b";
} elseif ($a == $b) {
echo "a is equal to b";
} elseif ($d == $b) {
echo "a is equal to b";
} else {
echo "a is smaller than b";
}
?>
<?php print $group_name; ?><br>
<a href="http://www.tekscan.com/contact-dental"><img src="<?=$img_src ?>" /></a>
<form action="" method="post" >
<input type="image" name="submit" value="Request Info" class="info-button" src="<?=$img_src ?>" />
<!-- product field -->
<input type="hidden" name="product" value="<?=$product_name ?>"/>
</form>
</div>
</div>
<?
答案 0 :(得分:0)
在他contact-us.php
文件行41中,您正在尝试打印$group_name
。但是,您没有在这两个文件中设置其值。 $content
的问题相同。看起来你可能错过了一个文件或一些文件。