3

For a Taxonomy Vocabulary on my Drupal 7 site, I have added several custom fields for each Taxonomy Term, and want to have two different ways of viewing the Term information: a summary and a detailed view.

I've created the two Views for summary and detailed (myterm-summary/% and myterm-detail/%). But now the question is how to create a link between them. I'd like a link on myterm-summary/% to link to myterm-detail/% as a "Read More..." link. Is there some View element I can add to the View to create a custom link, using the dynamic URL variable in the process?

I know I can create a Rich Text block header or footer for the View, but can I refer to the URL variable in that text block somehow?

4

I've found a solution that you can use the Replacement Tokens to this effect. In order for the field you want to show up as a possible Replacement Token, it must be in the Fields list. So I did:

  • Set Format to "Unformatted List"
  • Set Show to "Fields"
  • Add the "Term ID" field to Fields list.
  • During creation (or edit it afterward), check the "Exclude from display" box.
  • Create a new Footer element that's a "Global: Text Area" type.
  • Check the "Use replacement tokens" box
  • Insert <a href="/myterm-detail/[tid]">More Info...</a> in the box.
-1

You can use the "Global : Text Area" in the Header or Footer of the view to add the link. You can get the URL variable using a PHP snippet and use that to create a link. The following should work :

<?php  
$view = views_get_current_view();
print '<a href=\'/myterm-detail/'. $view->args[0] .'\'>Read More..</a>';
?>

Make sure you are using the PHP code text format.

  • I don't have a "PHP code" Text Format; is that an additional module? – MidnightLightning Oct 4 '12 at 19:11
  • Yes. Although it is included in the D7 core, you do have to enable it separately. Go to your modules page, under the core modules you will find a module called "PHP filter". Enable that. – bcosynot Oct 4 '12 at 19:27
  • 5
    Under no circumstances should you use php in a textarea or textfield in drupal! Forget the php filter completely! It will be removed from drupal 8 either. What do you do, if an api change happens on an update, and your site is broken, because a function was removed? Very happy to figure out, which textfield causes the problem.. – Gabor Szanto Oct 4 '12 at 19:31
  • Thanks @GaborSzanto. Additionally, if you have a PHP syntax error (which can be difficult to track if it's deeply down in some nested ifs e.g.) your site will go to a nice WSOD and you never find out again why. Have fun removing the culprit code then in the database tables using phpmyadmin or adminer. Never do that. PHP should not exist as database content in Drupal. – nerdoc Feb 5 '16 at 22:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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