Advertise Here | Advertise Here | Advertise Here | Advertise Here
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Attention buyers: Please take the time to read THIS
    Dismiss Notice
  3. I have imposed a new requirement today limiting who can start and receive private conversations. This is in an effort to thwart scammers who have a zero post count but private message others offering to sell their licenses. The restriction is not strict, a user must post at least one (1) post in the forum before being allowed to start and/or receive private conversations. Read Forum Post
    Dismiss Notice
  4. Dismiss Notice
Dismiss Notice
Introducing the new Classifieds Section

Please see HERE for more info.

Username Variable in XenForo Template

Discussion in 'General Chat' started by Dan, Jun 6, 2011.

  1. Dan

    Dan Admin Staff Member

    Local Time:
    2:10 AM
    Vincent! :p

    I am trying to add the code you gave me (below) into an addon so I don't have to manually edit the templates.
    HTML:
    <xen:if is="{$post.isFirst} AND !{$isQuickReply}">
    <center>
    <a href="conversations/add?to={$user.username}" title="Send a PM">Send a PM</a>
    </center>
    </xen:if>
    However, when called via a hook, none of the {} variables are working. What am I doing wrong?
     
  2. Vincent

    Vincent Here to help

    Local Time:
    9:10 AM
    This is normal.

    There are quite a few add-ons who use that, for example [LN] Blog :)
    Take a look at that.
    "It's better to learn Dan how to fish then catching him fish", so go learn how to do it :D
    If you really can't do it, feel free to contact me again :)
     
  3. Vincent

    Vincent Here to help

    Local Time:
    9:10 AM
  4. Dan

    Dan Admin Staff Member

    Local Time:
    2:10 AM
    Update: I got the username worked out but this
    HTML:
    <xen:if is="{$post.isFirst} AND !{$isQuickReply}">
    Still doesn't work. Off to play some more.
     
  5. Vincent

    Vincent Here to help

    Local Time:
    9:10 AM
    What you can do best is tell the hook to read the code from a new template.

    I have no idea how to do it the other way myself :D
     
  6. Xencored

    Xencored Member

    Local Time:
    8:10 AM
    I would not use center tag's ever on my site. The problems you can get from them are just not worth it imo
    use css to center it.
     
  7. Vincent

    Vincent Here to help

    Local Time:
    9:10 AM
    Yeah true,

    I've done it quickly previous time but I'm not sure on how far Dan is with adding this as a hook :D if he needs help he can contact me
     
  8. Dan

    Dan Admin Staff Member

    Local Time:
    2:10 AM
    well, right now I cannot get
    Code:
    {$post.isFirst}
    to pass to the hook, which is pretty important to the functionality we are trying to achieve. I thought I read that the $post variable will be exposed in 1.03. So I am not sure this is even possible at the moment. Once I get that variable passed, the only thing left to do is create a css template for the addon and we are golden.
    I think once I figure out what xenforo is doing, I will like it. Right now, I think vBulletin is much easier to code for.

     
  9. Xencored

    Xencored Member

    Local Time:
    8:10 AM
    Sometimes I think the same :/

    this might help I see your post above you have "AND" try "&&"
    example
    HTML:
    <xen:if is="!{$visitor.user_id} && !{$post.isFirst}">
     
  10. Dan

    Dan Admin Staff Member

    Local Time:
    2:10 AM
    Ah, right you are. However still doesn't pass. :confused: Close to posting on xenforo for help but want to make sure I don't make an ass out of myself :p
     
  11. Xencored

    Xencored Member

    Local Time:
    8:10 AM
    What are you trying to do? care to explain some more?
     
  12. Vincent

    Vincent Here to help

    Local Time:
    9:10 AM
    Mate, I have time tonight, I'll do it :)
    Then you can look at the code afterworth and learn out of it :D
     
  13. Dan

    Dan Admin Staff Member

    Local Time:
    2:10 AM
    @Vincent had a brilliant idea to add a "Send a Message" link to the OP in the Swap Shop section only to make it easier to make an offer. See screenshot. However, we only want this message to show on the OP. So all we are doing is checking if it is the first post, checking to make sure we are in the right forum (using array admin options to check node id) and displaying the link below the avatar.

    The problem: I have a template with the following contents (well it has since changed but doesn't matter)
    Code:
    <xen:if is="{$post.isFirst} AND !{$isQuickReply}">
    <center>
    <a href="conversations/add?to={$user.username}" title="Send a PM">Send a PM</a>
    </center>
    </xen:if>
    Works great by editing the correct template and using:
    Code:
    <xen:include template="whatever" />
    But the minute I call it with a templateHook listener, $post.isFirst dies.

    Clear as mud? :p

    Capture.JPG
     
  14. Xencored

    Xencored Member

    Local Time:
    8:10 AM
    Thought the idea of a forum is to post. Looking at this site the more content viewable to the public is better...
     
  15. Xencored

    Xencored Member

    Local Time:
    8:10 AM
    Works fine for me
    with a simple template edit.
    HTML:
    <xen:require css="message_user_info.css" />
    
    <div class="messageUserInfo" itemscope="itemscope" itemtype="http://data-vocabulary.org/Person">
    <div class="messageUserBlock">
        <xen:hook name="message_user_info_avatar" params="{xen:array 'user={$user}', 'isQuickReply={$isQuickReply}'}">
            <div class="avatarHolder">
                <xen:avatar user="$user" size="m" />
                <!-- slot: message_user_info_avatar -->
            </div>
        </xen:hook>
    
    <xen:if is="!{$isQuickReply}">
        <xen:hook name="message_user_info_text" params="{xen:array 'user={$user}', 'isQuickReply={$isQuickReply}'}">
            <h3 class="userText">
                <xen:username user="$user" itemprop="name" rich="true" />
                <xen:if hascontent="true"><em class="userTitle" itemprop="title"><xen:contentcheck>{xen:helper userTitle, $user}</xen:contentcheck></em></xen:if>
                <!-- slot: message_user_info_text -->
            </h3>
        </xen:hook>
    
        <xen:if hascontent="true">
            <div class="extraUserInfo">
                <xen:contentcheck>
    <xen:if is="{$post.isFirst} AND !{$isQuickReply}">
    <a href="http://localhost/index.php?conversations/add&to={$user.username}" title="Send a PM">Send a PM</a>
    </xen:if>
                <xen:hook name="message_user_info_extra" params="{xen:array 'user={$user}', 'isQuickReply={$isQuickReply}'}">
                    <xen:if is="@messageShowRegisterDate">
                        <dl class="pairsInline">
                            <dt>{xen:phrase member_since}:</dt>
                            <dd>{xen:date $user.register_date}</dd>
                        </dl>
                    </xen:if>
    
                    <xen:if is="@messageShowMessageCount">
                        <dl class="pairsInline">
                            <dt>{xen:phrase message_count}:</dt>
                            <dd><a href="{xen:link search/member, '', 'user_id={$user.user_id}'}" class="concealed">{xen:number $user.message_count}</a></dd>
                        </dl>
                    </xen:if>
    
                    <xen:if is="@messageShowTotalLikes">
                        <dl class="pairsInline">
                            <dt>{xen:phrase likes_received}:</dt>
                            <dd>{xen:number $user.like_count}</dd>
                        </dl>
                    </xen:if>
    
                    <xen:if is="@messageShowTrophyPoints">
                        <dl class="pairsInline">
                            <dt>{xen:phrase trophy_points}:</dt>
                            <dd><a href="{xen:link 'members/trophies', $user}" class="OverlayTrigger concealed">{xen:number $user.trophy_points}</a></dd>
                        </dl>
                    </xen:if>
    
                    <xen:if is="@messageShowGender AND {$user.gender}">
                        <dl class="pairsInline">
                            <dt>{xen:phrase gender}:</dt>
                            <dd itemprop="gender"><xen:if is="{$user.gender} == 'male'">{xen:phrase male}<xen:else />{xen:phrase female}</xen:if></dd>
                        </dl>
                    </xen:if>
    
                    <xen:if is="@messageShowOccupation AND {$user.occupation}">
                        <dl class="pairsInline">
                            <dt>{xen:phrase occupation}:</dt>
                            <dd itemprop="role">{xen:string censor, $user.occupation}</dd>
                        </dl>
                    </xen:if>
    
                    <xen:if is="@messageShowLocation AND {$user.location}">
                        <dl class="pairsInline">
                            <dt>{xen:phrase location}:</dt>
                            <dd><a href="{xen:link 'misc/location-info', '', 'location={xen:string censor, $user.location}'}" target="_blank" rel="nofollow" itemprop="address" class="concealed">{xen:string censor, $user.location}</a></dd>
                        </dl>
                    </xen:if>
    
                    <xen:if is="@messageShowHomepage AND {$user.homepage}">
                        <dl class="pairsInline">
                            <dt>{xen:phrase home_page}:</dt>
                            <dd><a href="{xen:string censor, $user.homepage}" rel="nofollow" target="_blank" itemprop="url">{xen:string censor, $user.homepage}</a></dd>
                        </dl>
                    </xen:if>
    
                    <xen:comment>
                    <xen:foreach loop="{$user.identities}" key="$service" value="$account">
                        <dl class="pairsInline">
                            <dt>{$service}</dt>
                            <dd>{$account}</dd>
                        </dl>
                    </xen:foreach>
                    </xen:comment>
    
                </xen:hook>
                </xen:contentcheck>
            </div>
        </xen:if>
    
    </xen:if>
    
        <span class="arrow"><span></span></span>
    </div>
    </div>
    fine.jpg
     
  16. Vincent

    Vincent Here to help

    Local Time:
    9:10 AM
    Could you give me temporary FTP and Admin mod at the site?
    You can remove it afterworth :D

    I'll create the hook and explain it after :)
     
  17. Vincent

    Vincent Here to help

    Local Time:
    9:10 AM
    @Vodka
    Well, I hope you understand some sellers don't like to talk business in public ;)

    And we already got that, but Dan is trying to do it with a hook and he doesn't know how :(
    Therefor I'll create the mod to learn :D
     
  18. Dan

    Dan Admin Staff Member

    Local Time:
    2:10 AM
    Yes, it does work when editing the template, but when calling that code with a templateHook, it does not.

    Yes sir, give me a minute.
     
  19. Xencored

    Xencored Member

    Local Time:
    8:10 AM
    Ah I see such a small mod :) am lazy template edit would do fine for me :D
     
  20. Vincent

    Vincent Here to help

    Local Time:
    9:10 AM
    Thanks :D
    And I had that error too in the beginning :p
    Now, after seeing some code, I understand ;)
     

Share This Page