3

I have a views block to display only the titles of some few nodes. Titles linked to the single node. I want to have a CSS class .active added to the title's links when the linked path matches the actual called path. As mentioned in the comments below, I didn't got that class by default.

So I added a Global: PHP field right after I added and excluded a Content: Path field to access $row->path in the Global: PHP's output code field. But $row->path seems to be empty. dpm($row) gives me a path: NULL. Content: Path displayed gives me the right paths. But where's the path gone in the PHP field??? When was the moment it got nulled?

I still managed to do what I want with the nid. Though without the beautiful alias paths I'ld like to have.

9
  • if these titles are linked, then there is nothing to do. The active link should already have active class.
    – Jack-PL
    Commented Aug 16, 2013 at 10:06
  • 1
    Why are you using PHP rather than Views' own handling? This sounds like something Views will do out-of-the-box, though your question doesn't really explain the motivation. Commented Feb 3, 2015 at 11:02
  • 1
    I was suggesting that you need to explain more about what your PHP code is trying to do. Generally, if you want to generate a link to content, it's easy to get Views to do that so I was wondering why you had resorted to PHP. Commented Feb 3, 2015 at 11:21
  • 1
    Please explain why you are using PHP to achieve this. If you use the built-in Views link to content, you should get the active class automatically. Commented Feb 3, 2015 at 11:38
  • 1
    If the current page URL matches that of an A tag on your page, and if that tag was generated using the l() function (which it will if it was generated using Views), it should have the active class. If it doesn't, that is a different issue to the one you have raised here. Commented Feb 3, 2015 at 12:16

1 Answer 1

2

Found a workaround for using the alias path in Views PHP: [SOLVED] Views PHP $row->path showing Null

drupal_lookup_path('alias', 'node/' . $data->nid)

Question still unanswered. Will report issue.

0

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.