How do I print the output of a field as a link on node.tpl.php? How do I print the output of a field as a link on node.tpl.php? I'm able to print the raw output of a field using this:

&lt;?php $display = array('label' =&gt; 'hidden');
$view = field_view_field('node', $node, 'field_podcast_url', $display);
print drupal_render($view);?&gt;&lt;?php $display = array('label' =&gt; 'hidden');?&gt;


The problem occurs when I try to make it as a link using this method:

&lt;?php $display = array('label' =&gt; 'hidden'); 
$view = field_view_field('node', $node, 'field_podcast_url', $display); ?&gt;
&lt;a href="&lt;?php print drupal_render($view); ?&gt;"&gt;text&lt;/a&gt;


The output looks like this:

http://www.podtrac.com/pts/redirect.mp3/feeds.soundcloud.com/stream/211653270-scott-johnson-27-tms-846.mp3
">text 

and the link points to this:

http://controldaily.dev/&lt;div class=


I've looked around at solving this issue and can't find a solution. Anything else just shows nothing.
This looks like it's happening because you are trying to input the entire rendered field (including styling) into the links href.

As per the description:


  The field_view_value() function can be used to output a single formatted field  value, without label or wrapping field markup.


To use field_view_field, try something like:

if($node-&gt;type == 'article')
{
    $link_field = field_view_field('node', $node, 'field_href');
    print l(t($link_field['#items'][0]['safe_value']), $link_field['#items'][0]['safe_value']);
}


This example assumes a node of article type, and a field with a machine name field_href. running it through l() (despite using the safe value) will help ensure it is sanitised properly before being output.

You can also take a look at the Link field module:


  The link module can be count to the top 50 modules in Drupal
  installations and provides a standard custom content field for links.
  With this module links can be added easily to any content types and
  profiles and include advanced validating and different ways of storing
  internal or external links and URLs. It also supports additional link
  text title, site wide tokens for titles and title attributes, target
  attributes, css class attribution, static repeating values, input
  conversion, and many more.