0

Hello i would like to change the destination of a url in a node.tpl (in a view) from this-

<a href="<?php print $node_url; ?>">

to something like this-

<a href="[field_viewslink]">

where the field viewslink is a link field in the node itself.

I know i could do it if the view used fields but it doesnt its using a content teaser.

Anyone got any advice?

Thanks

sites/all/themes/other_sub/templates/nodes/node--view--portfolio-block.tpl.php

<li class="<?php print str_replace(',-', ' ', str_replace(' ', '-',strip_tags(render($content['field_portfolio_category'])))); ?>">
    <?php print render($content['field_portfolio_image']); ?>
    <div>
        <a href="<?php print render($content['field_viewslink']); ?>">
          <span class="center">
              <h4 class="heavy remove-bottom"><?php print $title; ?></h4>
              <p><?php print strtolower(render($content['field_portfolio_category'])); ?></p>
          </span>
        </a>
    </div>
</li>

3 Answers 3

1

If it is a field with in the node then you should be able to use the $node object.

The object contains all the fields associated with the node.

if you are not sure of the name of the field then you could try to print the object using the print_r function.

You could also try try the $content object which contains the fields as well.

print render($content['field_viewslink']);

That should render the variable.

9
  • thanks for the replies guys. I think Mohammed's way is more like the way that i am used to. I will edit my original post to put in the code i have now (which still links to the node funniliy enough)
    – Reg Gordon
    Commented May 19, 2014 at 9:58
  • Could you check the content of the $node variable by using print_r may be it will give you some clue. Commented May 19, 2014 at 10:01
  • ive added it to my pag.tpl whichy you can see here mohammed islifeshit.com but nothing showing. If they had simply done it with fields and not using teaser conent id be ok.
    – Reg Gordon
    Commented May 19, 2014 at 10:22
  • sorry the block view wasnt showing to non regustered guests. it is now. Ive tried prin r and devel and everything. It SHOULD work as it is but for some reason it isnt. im all drupal depressed. been at ut for 7 days solid. i give up for now i think :(
    – Reg Gordon
    Commented May 19, 2014 at 10:49
  • mmmm well ive finally got it down to showing an array. the field is being loaded in the view mohammed. Ach ill get there yet. Maybe ill go for a walk around the park to get my mind back
    – Reg Gordon
    Commented May 19, 2014 at 11:18
1

You can use template_preprocess_node function to modify value of node.tpl.php

e.g:

function MYTHEME_preprocess_node(&$variables) {
//$variables['node_url'] = url($uri['path'], $uri['options']);
$variables['node_url'] = url(YOUR-CUSTOM-URL);
}
0

finally got there with this

<a href="<?php print strip_tags(render($content['field_viewslink'])); ?>">

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.