XF 1.2 Need to put a conversation link in the message template

Matthew Hawley

Well-known member
I put this code in the message template and link only goes to /conversation/add instead of /conversation/add?to=user

Code:
<a href="{xen:link conversations/add, 'to={$user.username}'}" class="Tooltip" title="Start a Conversation"><b><font color="gray">Staff</font></b></a>

Any suggestions?
 
This will work:
Code:
<a href="{xen:link conversations/add, '', 'to={$user.username}'}" class="Tooltip" title="Start a Conversation"><b><font color="gray">Staff</font></b></a>

In a {xen:link the first parameter is the route/action. The second parameter is for an array of data, e.g. $user, $conversation, $thread, $post (depending on the link and data required). The third parameter is for any further GET parameters you need to pass to the link.

You may want to see these two resources:

http://xenforo.com/community/resources/start-conversation-from-post-ajax.1767/
http://xenforo.com/community/resources/start-conversation-from-post-bit.1250/
 
My code is definitely correct.

But it will probably be {$message.username} or {$post.username} depending on exactly which template you're using the code in.

You can't ever assume that the user information is stored in the $user variable. Most of the time, in fact, $user doesn't exist.

$visitor always exists because that's the currently logged in user and the $visitor var is available on pretty much every single page.

Where you're dealing with specific content, the user information will usually be within that content, rather than in a separate parameter.

Basic example is the $message var might look something like this:

PHP:
$message = array(
    'user_id' => 1,
    'username' => 'Chris Deeming'
    'post_id' => 1,
    'thread_id' => 1,
    'message' => 'Some message text'
);

So, in that example, if you need the username you would use {$message.username} instead of {$user.username}.
 
My code is definitely correct.

But it will probably be {$message.username} or {$post.username} depending on exactly which template you're using the code in.

You can't ever assume that the user information is stored in the $user variable. Most of the time, in fact, $user doesn't exist.

$visitor always exists because that's the currently logged in user and the $visitor var is available on pretty much every single page.

Where you're dealing with specific content, the user information will usually be within that content, rather than in a separate parameter.

Basic example is the $message var might look something like this:

PHP:
$message = array(
    'user_id' => 1,
    'username' => 'Chris Deeming'
    'post_id' => 1,
    'thread_id' => 1,
    'message' => 'Some message text'
);

So, in that example, if you need the username you would use {$message.username} instead of {$user.username}.

{$message.username} worked. Thank you!
 
Back
Top Bottom