I have several fields in my view:
- Path (excluded from display)
- Image
- Body
- Button (rewritten to use [path])
I need to output the image like so (this is a requirement):
<a href='[path]' style='background: url([image]);'>TITLE</a>
I cannot do this using rewrite rules because of https://www.drupal.org/node/417956 which explains that views runs all rewrites through filter_xss_admin()
. This function strips out the style attribute on the a tag.
I am attempting to implement this in a view template, specifically the Field Content: Image (ID: Image)
template:
<?php
/**
* @file
* 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.
*/
?>
<a href='/' style='background-image: url(<?php print $output; ?>);'><?php print $row->node_title; ?></a>
I have tried this, [path] remains unchanged:
<a href='[path]' style='background-image: url(<?php print $output; ?>);'><?php print $row->node_title; ?></a>
and this, [path] remains unchanged:
<a href='<?php print token_replace("[path]", array('node' => $row->_field_data['nid']['entity'])); ?>' style='background-image: url(<?php print $output; ?>);'><?php print $row->node_title; ?></a>
I cannot find the value of the path anywhere in any of the variables. How can I output the value of [path] in my view template?