【问题标题】:Checking parameter classes in PHP检查 PHP 中的参数类
【发布时间】:2011-11-23 17:47:30
【问题描述】:

目前,我有以下内容:

<?php if ($custom != ""): ?> 
    <div class="head-row5" id="custom">
        <?php print $custom?>                    
    </div><?php //head-row5 ?>                  
<?php endif; ?>

返回的内容类似于....

<div class="block block-block" id="block-block-15">
    <div class="title">
        <h3></h3>
    </div>
    <div class="content"><p style="text-align: center;"><a href="website linkage" id="T2roll"><span class="alt">Name of the linked page</span></a></p>
</div>

我要做的是找到一种方法,仅当&lt;span class="alt"&gt; 为真时才打印出来。

我该怎么做?

我相信我将不得不按这个 $custom 参数的类来检查元素。但是,我不知道该怎么做。

【问题讨论】:

  • 我解决这个问题的方法是在最初的声明中。我希望能够说出以下内容: if(($custom != "") && (!property_exists($custom, 't2roll')) THEN include it。
  • 我看不到您的两个代码示例之间的联系。第二个代码块是$custom 的值还是什么?您要检查&lt;span class="alt"&gt; 是否包含在$custom 中?在您的第二个块中,您还缺少class=content-div 的结束 div。
  • @lorem 是的,它的工作方式是 $custom 经过四个不同的地方并将 &lt;div class="head-row5" id="custom"&gt;&lt;/div&gt; 附加到它。

标签: php html drupal


【解决方案1】:
function mytheme_preprocess_block(&$vars) {
  if ($vars['block_id'] === 'target_block_id') {
    // do something for this block

  }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-08
    • 2011-06-10
    • 1970-01-01
    • 1970-01-01
    • 2015-05-19
    • 1970-01-01
    • 2020-08-25
    • 1970-01-01
    相关资源
    最近更新 更多