0

I'm using the Message module to notify users when someone reacted on their nodes. I'm now trying to theme the messages, which are displayed in a view, called 'Message'.

I'd like to link a message to the content that's commented on. In other words: when a user clicks a message, he/she should be linked to the corresponding node's page. I don't simply want the message text to be a link, but the whole message (i.e. also including the other fields) should function as some kind of 'button'.

I think the easiest way to do this is to create a views-view-unformatted--message.tpl.php file and use

<?php foreach ($rows as $id => $row): ?>
  <div<?php if ($classes_array[$id]) { print ' class="' . $classes_array[$id] .'"';  } ?>>
   <a href="<?php print url('$url'); ?>">
    <?php print $row; ?>
   </a>
  </div>
<?php endforeach; ?>

The problem is that I don't know how to define $url. I can store the needed nid in the message and add it hidden to the view, but I can't find a way to grab that information.

How can I do that?

1

I stored the nid from the node that's commented on in a message field and used the information in a views-view-unformatted--message.tpl.php file.

<?php if (!empty($title)): ?>
  <h3><?php print $title; ?></h3>
<?php endif; ?>
<?php foreach ($rows as $id => $row): ?>
  <?php $message = message_load($view->result[$id]->mid); ?>      
  <div <?php if ($classes_array[$id]) { print ' class="' . $classes_array[$id] .'"';  } ?>>
   <a href="<?php if (isset ($message->field_nid['und'][0]['value'])) {
                      print url('node/'.$message->field_nid['und'][0]['value']);} ?>">
    <?php print $row; ?>
   </a>
  </div>
<?php endforeach; ?>

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.