多值字段的主题视图

发布于 2024-11-17 15:35:04 字数 318 浏览 2 评论 0原文

我知道这可能是一个n00b问题,但我到处寻找答案但没有找到任何东西。

我有一个“功能”的 CCK 多值字段,其中产品可以输入随机数量的多个功能。我正在编辑视图,以便可以在产品页面上设置功能输出的样式。

现在,在我看来,我可以使用以下命令立即输出整个功能列表:

<?php print $fields['field_features_value']->content ?> 

这将为我提供产品给出的所有功能的列表。但我想做的是循环遍历并提取每个单独的功能,并分别对其进行格式化/样式设置。我到底该怎么做呢?

I know this is probably a n00b question but I've searched everywhere for an answer and havent found anything.

I have a CCK multiple value field for "Features" where a product can have a random number of multiple features entered for it. I am editing the view so I can style the output of the features on the product page.

Right now in my view I can output the entire list of features at once using:

<?php print $fields['field_features_value']->content ?> 

This will give me a list all the features given for a product. But what I want to do is loop through and pull out each individual feature and format/style it separately. How exactly would I do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

暮色兮凉城 2024-11-24 15:35:04

我昨天再次遇到这个问题,花了几个小时尝试谷歌语法,但无济于事。

我能够让它发挥作用,但我必须承认这不是最好的方法。它重复了 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 这里大量使用模块(附加了此示例的图像参考),以便获得我需要的嵌套值。

Devel view of fields used

我知道有一种更好、更正确的方法来执行此操作,而不是重新加载节点数据,因为视图应该在页面加载时已经可以访问它。

I ran into this yesterday again, and spent hours trying to Google the syntax, to no avail.

I was able to get this to work, but I must admit it is not the best way. It is duplicating some of the work that Views has already potentially done for us, and should be considered a brute-force approach.

My use case involved theming each filefield file in a node separately, per node-based row:

<?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>';
    }

?>

I used the Devel module heavily here (image reference for this example attached), in order to get the nested values I needed.

Devel view of fields used

I know there is a better, proper way of doing this, rather than reloading the node data, since views should already have access to this upon page load.

蓝色星空 2024-11-24 15:35:04

当主题视图过于具体时,我会设置条件、关系、参数和所有视图内容除了字段。我使用的唯一字段是节点 ID。

然后,在进行主题化时,我使用...

$node = node_load($nid);

...来获取节点对象。您可以使用 devel 模块附带的 dpm 函数检查节点对象。

dpm($node);

这种“技术”适用于节点,并且当您不关心优化或速度时,因为如果您要使用 1000 个节点执行此操作,则应该批量加载节点。

When theming views is too specific I set conditions, relationships, parameters and all the views stuff except fields. The only field I use is node id.

Then when doing the theming I use...

$node = node_load($nid);

... to get the node object. You can inspect the node object with the dpm function that comes with the devel module.

dpm($node);

This "technique" works well for nodes and when you don't care about optimization or speed, because if you are going to do this with 1000 nodes you should load the nodes on batch.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文