Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

I've been trying to understand this for a while now, but I find the documentation either to lacking, or maybe I just don't understand what I'm looking for. Could anyone enlighten me on how to implement them?

One thing I'm trying to do is to be able to have contextual menus for each node in a list of nodes (loaded using node_load_multiple) that I'm sending along to a theme() function and looping through inside the .tpl.php

share|improve this question
add comment

1 Answer

I'm not really into answering my own questions, especially when I'm pretty sure this is not the correct way to do it, but I'll put my temporary solution here for now anyway in case it will help someone.

What I did was just creating a new theme function (?) in my module

$themes['contextual'] = array(
    'template' => 'contextual',
    'variables' => array('links' => array(), 'destination' => null)
);

Then I defined my contextual.tpl.php

<div class="contextual-links-wrapper">
    <ul class="contextual-links">
        <?php foreach($links as $url => $title): ?>
        <li>
            <?php echo l($title, $url, 
                array('query' => array('destination' => $destination))) ?>
        </li>
        <?php endforeach; ?>
    </ul>
</div>

Finally, to use it, wherever there is a need for a contextual menu, add the class contextual-links-region to the container div of the node (or whatever), and inside the div I use my function, for example:

<?php echo theme('contextual', array('destination' => 'node/'.arg(1),
    'links' => array('node/'.$somenode->nid.'/edit', t('Edit node')))); ?>
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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