多值字段的主题视图

| 我知道这可能是一个n00b问题,但是我到处都在寻找答案,却没有找到任何答案。 我有一个\“ Features \”的CCK多个值字段,其中产品可以为它输入随机数量的多个功能。我正在编辑视图,以便可以在产品页面上设置功能的输出样式。 现在在我看来,我可以使用以下命令一次输出整个功能列表:
<?php print $fields[\'field_features_value\']->content ?> 
这将为我列出产品的所有功能。但是我要做的是循环遍历并提取每个单独的功能,并分别设置格式/样式。我到底要怎么做?     
已邀请:
        昨天我又遇到了这个问题,花了数小时尝试使用Google语法,但无济于事。 我能够做到这一点,但是我必须承认这不是最好的方法。它正在复制Views已经为我们完成的某些工作,应该被认为是蛮力方法。 我的用例涉及针对每个基于节点的行分别为节点中的每个文件字段文件设置主题:
<?php
// $Id: views-view-field.tpl.php,v 1.1 2008/05/16 22:22:32 merlinofchaos Exp $
 /**
  * This template is used to print a single field in a view. It is not
  * actually used in default Views, as this is registered as a theme
  * function which has better performance. For single overrides, the
  * template is perfectly okay.
  *
  * Variables available:
  * - $view: The view object
  * - $field: The field handler object that can process the input
  * - $row: The raw SQL result that can be used
  * - $output: The processed output that will normally be used.
  *
  * When fetching output from the $row, this construct should be used:
  * $data = $row->{$field->field_alias}
  *
  * The above will guarantee that you\'ll always get the correct data,
  * regardless of any changes in the aliasing that might happen if
  * the view is modified.
  */
?>
<?php

$output = explode(\'|\', $output); // I\'ve rewritten the field output in Views like this: [field_portfolio_image-field_name]|[nid]
$paths = $output[0]; // I\'ve set filefield to show file paths rather than the file
$nid = $output[1]; // The NID is all that\'s really needed for this approach

$node = node_load($nid);
$slots = $node->field_portfolio_image;

foreach($slots as $prop) {
        print \'<a href=\"\'.$prop[filepath].\'\" title=\"\'.$prop[data][description].\'\" rel=\"gallery-\'.$nid.\'\" class=\"colorbox hidden\">\'.$prop[data][description].\'</a>\';
    }

?>
为了获得所需的嵌套值,我在这里大量使用了Devel模块(此示例附有图像参考)。 我知道有一个更好,更适当的方法,而不是重新加载节点数据,因为视图在页面加载时应该已经可以访问此数据。     
        当主题视图过于具体时,我会设置条件,关系,参数和所有视图内容(字段除外)。我使用的唯一字段是节点ID。 然后在做主题时我用...
$node = node_load($nid);
...以获取节点对象。您可以使用devel模块随附的dpm功能检查节点对象。
dpm($node);
此“技术”对于节点非常有效,并且当您不关心优化或速度时,因为如果要使用1000个节点来执行此操作,则应批量加载节点。     

要回复问题请先登录注册