I'm working on a theme where the links need to be split around node.tpl.php in various places, and of course need to appear only when relevant. Unfortunately I can't just test for $links[n] and then punch that into the template where required because the array changes with the available and relevant links to the node. Some of the links such as email and print and so on, privatemsg that type of thing can all be hard coded without $links[], but the edit, quote, comment and reply items are the variables here, that may be disabled for certain nodes, but I don't know an easy way to check for their existence other than stepping through $links[] and testing for each instance.

I've read everything I could find on this site about $links at:
http://drupal.org/node/44708 and
http://drupal.org/node/49393#comment-92915
but neither of those helps me with this question.

Maybe I just need to step through $link[] and test for each and then use that to control the display of hardcoded links?

I don't know if anyone has done this before or not, but if I end up doing this myself I will post snippets here.

I kinda wanna do the same thing with terms and submitted, but at least those can be broken down through $node[] and $taxonomy[] (I haven't tried this, but it seems like it'd be very easy to do). Thanks!

-Mike

Comments

sin’s picture

Once when I need to add a class="blabla" attribute to particular link.
I heared in Drupal 4.8 $links[] will contain subarrays, not a html links.

mikey_p’s picture

I can step through them I just never know where the links are going to show up at, for instance on one node they may be ( I don't know where this first quote link is coming from either...it links to javascript:void(null);)

[links] => Array
        (
            [0] => quote
            [1] => add new comment
            [2] => email this page
            [3] => printer friendly version
            [4] => quote
        )

While another node with comments disabled might have this:

[links] => Array
        (
            [0] => quote
            [1] => email this page
            [2] => printer friendly version
        )

So anywhere I would have used $links[1] for add new comment in the first example, would now have email this page.

I know I could just step through all the array and check to see if 'add new comment' is set and if it is, then display the link, but ideally there might be a sub array to set this up, and in the spirit of my recent discovery of the CCK, something like this maybe:

[links_array] => Array
        (
            [0] => Array
                (
                    [value] => email_this_page
                    [set] => 1
                    [view] => <a href="http://linktoemailthispage">email this page</a>
                    [weight] => 0
                    [description] => email this page to a friend
                )
                [1] => Array
                (
                    [value] => print
                    [set] => 1
                    [view] => <a href="http://linktoprintthispage">printer friendly version</a>
                    [weight] => 0
                    [description] => displays a version of this page for printing
                )                
            [2] => Array
                (
                    [value] => add_new_comment
                    [set] => 0
                    [view] => <a href="http://linktoaddnewcomment">add new comment</a>
                    [weight] => 0
                    [description] => click here to add a new comment
                )

        )
        

Obviously this would be expanded to include all the links, read more,edit and quote, etc. The set field would be whether or not that link should be visible on that page or not.

Maybe I'm just dreaming here, but that would be awesome. In a fantasy world this [links_array] would be available to page.tpl.php as well as node.tpl.php.

-Mike

mikey_p’s picture

The main thing I was looking for was to see if comments are allowed before printing a 'add new comment' or 'reply' link, I don't know how I missed looking at $comment in node, but doing that should allow everything I need. Although I still wish there was an easier way to determine that status of email and print links, but those aren't so critical, as the only ones that seem to change state that I need are 'read more' and comment related links.

Thanks anyway, although I do wish that the above mentioned array were implemented or something similar.

-Mike

mikey_p’s picture

Even cooler solution to be found at http://drupal.org/node/21538#comment-81773

It may need some updates for 4.7 but other wise basically answers my questions.

-Mike