【问题标题】:Check if field is empty and hide a css class in render array检查字段是否为空并在渲染数组中隐藏一个 CSS 类
【发布时间】:2015-11-23 13:17:39
【问题描述】:

我是 drupal 核心开发的新手,任何帮助将不胜感激。 I have a tab group from content type hidden from anonymous users (by default) when the field content within the tab is empty, how do I hide this tab when login in editors are viewing the same content.

这是我迄今为止在 node.inc 中使用 template_preprocess_node 所做的事情

function template_preprocess_node__event(&$variables, $hook) 
{
//  kpr($variables);
$node = $variables['node'];
//  kpr($node);
$custom_tab = field_get_items('node', $variables['node'], 'field_route_text');
$custom_tab = (!empty($custom_tab)) ? kpr ('not empty from node') :  kpr('empty from node');

// jQuery UI accordion lib
drupal_add_library('system', 'ui.accordion');
}

【问题讨论】:

    标签: php css drupal-7


    【解决方案1】:

    我通过下面的代码实现了这一点;

    function template_preprocess_node__event(&$variables, $hook) {
    $node = $variables['node'];
    $custom_tab = field_get_items('node', $variables['node'],    'field_override_group_label')
    if (! isset($custom_tab[0]['safe_value'])){
        drupal_add_css(drupal_get_path('theme', 'template some') . "/css/customtab.css");
    }
    // jQuery UI accordion lib
    drupal_add_library('system', 'ui.accordion');
    

    }

    在 customtab.css 文件中,我添加了一个 css 来隐藏类。 我认为这可能会对网站的整体性能产生影响。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-12-02
      • 1970-01-01
      • 2014-02-02
      • 1970-01-01
      • 2015-09-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多