Replacement Tokens in View Template 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):

&lt;a href='[path]' style='background: url([image]);'&gt;TITLE&lt;/a&gt;


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:

&lt;?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-&gt;{$field-&gt;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.
 */
?&gt;
&lt;a href='/' style='background-image: url(&lt;?php print $output; ?&gt;);'&gt;&lt;?php print $row-&gt;node_title; ?&gt;&lt;/a&gt;


I have tried this, [path] remains unchanged:

&lt;a href='[path]' style='background-image: url(&lt;?php print $output; ?&gt;);'&gt;&lt;?php print $row-&gt;node_title; ?&gt;&lt;/a&gt;


and this, [path] remains unchanged:

&lt;a href='&lt;?php print token_replace("[path]", array('node' =&gt; $row-&gt;_field_data['nid']['entity'])); ?&gt;' style='background-image: url(&lt;?php print $output; ?&gt;);'&gt;&lt;?php print $row-&gt;node_title; ?&gt;&lt;/a&gt;


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?
Can you get the node id you are aiming for? If so, try using drupal_get_path_alias()

$linknid = $fields['field_link_to_content']-&gt;content;

$alias = drupal_get_path_alias('node/' . $linknid);

&lt;a href='&lt;?php print $alias; ?&gt;' style='background-image: url(&lt;?php print $output; ?&gt;);'&gt;&lt;?php print $row-&gt;node_title; ?&gt;&lt;/a&gt;


UPDATE - this is how I did it, based on this answer:

&lt;a href='&lt;?php print drupal_get_path_alias('node/' . $row-&gt;nid); ?&gt;' style='background-image: url(&lt;?php print $output; ?&gt;);'&gt;&lt;?php print $row-&gt;node_title; ?&gt;&lt;/a&gt;