1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

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

Discussion in 'Styling and Customization Questions' started by Matthew Hawley, Aug 24, 2013.

  1. Matthew Hawley

    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?
     
  2. Chris D

    Chris D XenForo Developer Staff Member

    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/
     
  3. Matthew Hawley

    Matthew Hawley Well-Known Member

    It didn't work.
     
  4. Chris D

    Chris D XenForo Developer Staff Member

    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}.
     
  5. Matthew Hawley

    Matthew Hawley Well-Known Member

    {$message.username} worked. Thank you!
     
    Chris D likes this.

Share This Page