Tổng hợp xenforo code Conditionals phần 1

Thảo luận trong 'Mã nguồn Xenforo - VBB' bắt đầu bởi phamcongson, 21/11/15.

  1. phamcongson
    Tham gia ngày:
    3/6/13
    Bài viết:
    474
    Đã được thích:
    93
    Điểm thành tích:
    28
    Giới tính:
    Nam
    The following conditional statements will only work in templates which support the arguments and parameters.

    Statements can be expanded using AND, OR, and <xen:else />.

    Replacing == with != in the following examples will change the condition from true to false.

    For example, <xen:if is="{$visitor.user_id} == x"> for true, <xen:if is="{$visitor.user_id} != x">for false.

    Where an argument only contains a single parameter, inserting a ! before the parameter has the same effect.

    For example, <xen:if is="{$visitor.user_id}"> for true, <xen:if is="!{$visitor.user_id}"> for false.

    When working with arrays, the ! is placed just before the argument.

    For example, <xen:if is="in_array({$forum.node_id}, array(x, y, z))"> for true, <xen:if is="!in_array({$forum.node_id}, array(x, y, z))"> for false.

    Depending on the template being worked with, you may need to use $user instead of $visitor; $visitor is always the record for the current logged in user, $user is the record being processed (e.g. message author, member list, list of online users, etc.).

    When working with the PAGE_CONTAINER template, you can pass variables from the view templates (category_view, forum_view, thread_view, etc.) using xen:container. The same applies to any templates which are included in the PAGE_CONTAINER template; the header or ad_header templates for example.
    To use the $forum.node_id variable for example, you would add this to the PAGE_CONTAINER template: <xen:container var="$forumId">{$forum.node_id}</xen:container>.
    Similarly for the $threadId variable, you would add this: <xen:container var="$threadId">{$thread.thread_id}</xen:container>.

    Where variables such as x, y, or z have been used, these must be replaced with actual values.

    How can I show content just to logged in members and hide it from guests?
    Mã:
    <xen:if is="{$visitor.user_id}">
    This content will show to logged in members
    </xen:if>
    
    How can I show content just to guests and hide it from logged in members?
    Mã:
    <xen:if is="!{$visitor.user_id}">
    This content will show to guests
    </xen:if>
    
    How can I show different content to guests and logged in members?
    Mã:
    <xen:if is="{$visitor.user_id}">
    This content will show to logged in members
    <xen:else />
    This content will show to guests
    </xen:if>
    
    How can I show content to a specific user group?
    Mã:
    <xen:if is="{xen:helper ismemberof, $visitor, x}">
    This content will show to members of user group x
    </xen:if>
    
    How can I hide content from a specific user group?
    Mã:
    <xen:if is="!{xen:helper ismemberof, $visitor, x}">
    This content will be hidden from members of user group x
    </xen:if>
    How can I show content to more than one user group?
    Mã:
    <xen:if is="{xen:helper ismemberof, $visitor, x, y}">
    This content will show to members of user groups x or y
    </xen:if>
    How can I hide content from more than one user group?
    Mã:
    <xen:if is="!{xen:helper ismemberof, $visitor, x, y}">
    This content will be hidden from members of user groups x or y
    </xen:if>
    How can I show content to Administrators?
    Mã:
    <xen:if is="{$visitor.is_admin}">
    This content will show to Administrators
    </xen:if>
    How can I show content to Moderators?
    Mã:
    <xen:if is="{$visitor.is_moderator}">
    This content will show to Moderators
    </xen:if>
    How can I show content to Administrators and Moderators?
    Mã:
    <xen:if is="{$visitor.is_admin} OR {$visitor.is_moderator}">
    This content will show to Administrators and Moderators
    </xen:if>
    How can I show content to a specific member?
    Mã:
    <xen:if is="{$visitor.user_id} == x">
    This content will show to member x
    </xen:if>
    
    How can I show content to more than one member?
    Mã:
    <xen:if is="in_array({$visitor.user_id}, array(x, y, z))">
    This content will show to members x, y and z
    </xen:if>
    How can I show content after the first post in a thread?
    Mã:
    <xen:if is="{$post.position} == 0 AND !{$message.conversation_id}">
    This content will show after the first post in a thread
    </xen:if>
    How can I show content after the first post in a thread or conversation?
    Mã:
    <xen:if is="{$post.position} == 0">
    This content will show after the first post
    </xen:if>
    How can I show content after post x on every page in a thread?
    Mã:
    <xen:if is="{$post.position} % {$xenOptions.messagesPerPage} == x AND !{$message.conversation_id}">
    This content will show after post x on every page in a thread
    </xen:if>
    How can I show content after post x on every page in a thread or conversation?
    Mã:
    <xen:if is="{$post.position} % {$xenOptions.messagesPerPage} == x">
    This content will show after post x on every page
    </xen:if>
    How can I show content after post x on every page, only in forums y and z?
    Mã:
    <xen:if is="{$post.position} % {$xenOptions.messagesPerPage} == x AND in_array({$thread.node_id}, array(y, z))">
    This content will show after post x on every page, only in forums y and z
    </xen:if>
    How can I show content after post x on every page, except in forums y and z?
    Mã:
    <xen:if is="{$post.position} % {$xenOptions.messagesPerPage} == x AND !in_array({$thread.node_id}, array(y, z))">
    This content will show after post x on every page, except in forums y and z
    </xen:if>
    How can I show content on a specific page?
    Mã:
    <xen:if is="{$contentTemplate} == 'xyz'">
    This content will show on the xyz template
    </xen:if>
    How can I show content in a specific category?
    Mã:
    <xen:if is="{$category.node_id} == x">
    This content will show in category x
    </xen:if>
    Note that in order for this to work, you must have categories set as pages in the ACP -> Options -> Node & Forum List: Create Pages for Categories.

    How can I show content in a specific forum?
    Mã:
    <xen:if is="{$forum.node_id} == x">
    This content will show in forum x
    </xen:if>
    How can I show content in more than one forum?
    Mã:
    <xen:if is="in_array({$forum.node_id}, array(x, y, z))">
    This content will show in forums x, y, and z
    </xen:if>
    How can I show content in a specific thread?
    Mã:
    <xen:if is="{$threadId} == x">
    This content will show in thread x
    </xen:if>
    How can I show content in more than one thread?
    Mã:
    <xen:if is="in_array({$threadId}, array(x, y, z))">
    This content will show in threads x, y, and z
    </xen:if>
    How can I show content in a specific post?
    Mã:
    <xen:if is="{$postId} == x">
    This content will show in post x
    </xen:if>
    How can I show content in more than one post?
    Mã:
    <xen:if is="in_array({$postId}, array(x, y, z))">
    This content will show in posts x, y, and z
    </xen:if>
    How can I show content to the thread author?
    Mã:
    <xen:if is="{$thread.user_id} == x">
    This content will show to thread author x
    </xen:if>
    How can I show content if the post author is the thread author?
    Mã:
    <xen:if is="{$post.user_id} == {$thread.user_id}">
    This content will show if the post author is the thread author
    </xen:if>
    How can I show content to members with 0 posts?
    Mã:
    <xen:if is="{$visitor.message_count} == 0">
    This content will show to members with 0 posts
    </xen:if>
    How can I show content to members with more than x posts?
    Mã:
    <xen:if is="{$visitor.message_count} > x">
    This content will show to members with more than x posts
    </xen:if>
    How can I show content to members with less than x posts?
    Mã:
    <xen:if is="{$visitor.message_count} < x">
    This content will show to members with less than x posts
    </xen:if>
    How can I show content to members who have not confirmed their email address?
    Mã:
    <xen:if is="{$isAwaitingEmailConfirmation}">
    This content will show to members who have not confirmed their email address
    </xen:if>
    How can I show content to visitors arriving from search engines?
    Mã:
    <xen:if is="{$visitor.from_search}">
    This content will show to visitors arriving from search engines
    </xen:if>
     
    Cảm ơn đã xem bài:

    Tổng hợp xenforo code Conditionals phần 1



Chủ để tương tự : Tổng hợp
Diễn đàn Tiêu đề Date
Mã nguồn Xenforo - VBB Tổng hợp xenforo code Conditionals phần 2 21/11/15
Mã nguồn Xenforo - VBB Gamebank hỗ trợ tích hợp đa dạng các mã nguồn 7/10/14