简体   繁体   English

在drupal视图中用字段链接包装输出

[英]Wrap output with link from field in drupal views

I have a view that is outputting a list of nodes that contain a link, image and text. 我有一个视图,该视图输出包含链接,图像和文本的节点列表。

I want to use the link field to wrap the output (rather than link to the node), but I can't figure out how to get the raw url/title etc to create create that link in the template. 我想使用链接字段来包装输出(而不是链接到节点),但是我不知道如何获取原始的url / title等来在模板中创建该链接。

The field is configured to output the url as plain text, but is wrapped in div/spans regardless of the style settings for the view field. 该字段被配置为以纯文本形式输出url,但是无论视图字段的样式设置如何,该字段都以div / span格式包装。

views-view-fields--my-view.php: views-view-fields--my-view.php:

<a href="<?php echo $fields['field_link']->content ?>">
<?php foreach ($fields as $id => $field):
    if ($id == 'field_link') continue;
    ?>
  <?php if (!empty($field->separator)): ?>
    <?php print $field->separator; ?>
  <?php endif; ?>

  <?php print $field->wrapper_prefix; ?>
    <?php print $field->label_html; ?>
    <?php print $field->content; ?>
  <?php print $field->wrapper_suffix; ?>
<?php endforeach; ?>
</a>

This produces: 这将产生:

<a href="<div class=" data-thmr="thmr_72"><div class="field-items"><div class="field-item even"><span data-thmr='thmr_24' class='devel-themer-wrapper'>/drupal/%237digital-buy</span></div></div></div>">
   [...]
</a>

Which is obviously not what I need. 显然这不是我所需要的。

Found the solution. 找到了解决方案。 You need to rewrite the output. 您需要重写输出。 See below. 见下文。

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM