- Para XenForo...
-
- 1.0.x
- 1.1.x
- 1.2.x
- 1.3.x
- 1.4.x
- 1.5.x
- Autor
- Brogan
- Imagen del autor
- URL de XenForo
- http://xenforo.com/community/resources/conditional-statements.1604/
Las siguientes sentencias condicionales solo funcionan en plantillas que soporten los argumentos y tengan los parámetros.
Las sentencias pueden ampliarse usando AND, OR, xen:else y xen:elseif.
Reemplazar == con != en los siguientes ejemplos cambiará la condición de verdadera a falsa.
Por ejemplo, <xen:if is="{$visitor.user_id} == x"> para verdadero, <xen:if is="{$visitor.user_id} != x"> para falso.
Cuando un argumento solo contiene un parámetro, insertar un ! antes del mismo tiene el mismo efecto.
Por ejemplo, <xen:if is="{$visitor.user_id}"> para verdadero, <xen:if is="!{$visitor.user_id}"> para falso.
Cuando se trabaja con matrices, el ! se coloca justo antes del argumento.
Por ejemplo, <xen:if is="in_array({$forum.node_id}, array(x, y, z))"> para verdadero, <xen:if is="!in_array({$forum.node_id}, array(x, y, z))"> para falso.
Usando xen:else y xen:elseif, pueden incorporarse varias condiciones en una sentencia.
La forma más simple de usar xen:else es algo así como:
Una sentencia más avanzada con varias condiciones se logra usando xen:elseif más o menos como sigue:
Dependiendo de la plantilla, funcionará o no. Se puede usar $user en vez de $visitor; $visitor siempre es el registro del actual usuario que ha iniciado sesión, $user es el registro que se procesa (ej. autor del mensaje, lista de miembros, lista de usuarios conectados, etc.).
Cuando se trabaja con la plantilla PAGE_CONTAINER, pueden pasarse variables a las plantillas view (category_view, forum_view, thread_view, etc.) usando xen:container. Lo mismo es aplicable a cualquier plantilla incluida en la plantilla PAGE_CONTAINER; la plantilla header o ad_header por ejemplo.
Para usar la variable $forum.node_id por ejemplo, sólo hay que añadir a la plantilla PAGE_CONTAINER: <xen:container var="$forumId">{$forum.node_id}</xen:container>.
Similarmente para la variable $threadId, habrá que añadir: <xen:container var="$threadId">{$thread.thread_id}</xen:container>.
Cuando usamos variables como x, y, o z, deben reemplazarse con sus valores actuales.
How can I show content just to logged in members and hide it from guests?
<xen:if is="{$visitor.user_id}">
How can I show content just to guests and hide it from logged in members?
<xen:if is="!{$visitor.user_id}">
How can I show different content to guests and logged in members?
<xen:if is="{$visitor.user_id}">
How can I show content to a specific user group?
<xen:if is="{xen:helper ismemberof, $visitor, x}">
How can I hide content from a specific user group?
<xen:if is="!{xen:helper ismemberof, $visitor, x}">
How can I show content to more than one user group?
<xen:if is="{xen:helper ismemberof, $visitor, x, y}">
How can I hide content from more than one user group?
<xen:if is="!{xen:helper ismemberof, $visitor, x, y}">
How can I show content to Administrators?
<xen:if is="{$visitor.is_admin}">
How can I show content to Moderators?
<xen:if is="{$visitor.is_moderator}">
How can I show content to Administrators and Moderators?
<xen:if is="{$visitor.is_admin} OR {$visitor.is_moderator}">
How can I show content to a specific member?
<xen:if is="{$visitor.user_id} == x">
How can I show content to more than one member?
<xen:if is="in_array({$visitor.user_id}, array(x, y, z))">
How can I show content if the visitor is the user?
<xen:if is="{$visitor.user_id} == {$user.user_id}">
How can I show content after the first post in a thread?
<xen:if is="{$post.position} == 0 AND !{$message.conversation_id}">
How can I show content after the first post in a thread or conversation?
<xen:if is="{$post.position} == 0">
How can I show content after post x on every page in a thread?
<xen:if is="{$post.position} % {$xenOptions.messagesPerPage} == x AND !{$message.conversation_id}">
How can I show content after post x on every page in a thread or conversation?
<xen:if is="{$post.position} % {$xenOptions.messagesPerPage} == x">
How can I show content after post x on every page, only in forums y and z?
<xen:if is="{$post.position} % {$xenOptions.messagesPerPage} == x AND in_array({$thread.node_id}, array(y, z))">
How can I show content after post x on every page, except in forums y and z?
<xen:if is="{$post.position} % {$xenOptions.messagesPerPage} == x AND !in_array({$thread.node_id}, array(y, z))">
How can I show content on a specific page?
<xen:if is="{$contentTemplate} == 'xyz'">
How can I show content on pages with a sidebar?
<xen:if is="{$sidebar}">
How can I show content in a specific category?
<xen:if is="{$category.node_id} == x">
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.
Additionally, to ensure the category ID is available in the ad_ templates, the category_view template must be edited and the following code added: <xen:container var="$category.node_id">{$category.node_id}</xen:container>
How can I show content in a specific forum?
<xen:if is="{$forum.node_id} == x">
How can I show content in more than one forum?
<xen:if is="in_array({$forum.node_id}, array(x, y, z))">
How can I show content in all forums with a specific parent?
<xen:if is="{$forum.parent_node_id} == x">
How can I show content in a specific thread?
<xen:if is="{$threadId} == x">
How can I show content in more than one thread?
<xen:if is="in_array({$threadId}, array(x, y, z))">
How can I show content in a specific post?
<xen:if is="{$postId} == x">
How can I show content in more than one post?
<xen:if is="in_array({$postId}, array(x, y, z))">
How can I show content to the thread author?
<xen:if is="{$thread.user_id} == x">
How can I show content if the post author is the thread author?
<xen:if is="{$post.user_id} == {$thread.user_id}">
How can I show content to members with 0 posts?
<xen:if is="{$visitor.message_count} == 0">
How can I show content to members with more than x posts?
<xen:if is="{$visitor.message_count} > x">
How can I show content to members with less than x posts?
<xen:if is="{$visitor.message_count} < x">
How can I show content to members who are visible?
<xen:if is="{$user.visible}">
How can I show content to members who have an avatar?
<xen:if is="{$visitor.avatar_date} OR {$visitor.gravatar}">
How can I show content to members who do not have an avatar?
<xen:if is="!{$visitor.avatar_date} AND !{$visitor.gravatar}">
How can I show content to members who have completed a custom user field?
<xen:if is="{$visitor.customFields.field_id}">
Note that field_id must be replaced with the actual custom user field identifier.
How can I show content to members who have not confirmed their email address?
<xen:if is="{$isAwaitingEmailConfirmation}">
How can I show content to visitors arriving from search engines?
<xen:if is="{$visitor.from_search}">
Sólo visible a miembros:
Sólo visible a visitantes:
Sólo visible por administradores:
Sólo visible a moderadores:
Sólo visible a miembros con al menos 5 Mensajes:
Sólo visible al grupo 2:
Sólo visible a los grupos X, Y, Z:
Sólo visible en el listado de foros (index,también, pero sólo en la plantilla PAGE_CONTAINER):
Sólo visible en un (id de) foro:
Sólo visible en una discusión detallada:
Salud2
Las sentencias pueden ampliarse usando AND, OR, xen:else y xen:elseif.
Reemplazar == con != en los siguientes ejemplos cambiará la condición de verdadera a falsa.
Por ejemplo, <xen:if is="{$visitor.user_id} == x"> para verdadero, <xen:if is="{$visitor.user_id} != x"> para falso.
Cuando un argumento solo contiene un parámetro, insertar un ! antes del mismo tiene el mismo efecto.
Por ejemplo, <xen:if is="{$visitor.user_id}"> para verdadero, <xen:if is="!{$visitor.user_id}"> para falso.
Cuando se trabaja con matrices, el ! se coloca justo antes del argumento.
Por ejemplo, <xen:if is="in_array({$forum.node_id}, array(x, y, z))"> para verdadero, <xen:if is="!in_array({$forum.node_id}, array(x, y, z))"> para falso.
Usando xen:else y xen:elseif, pueden incorporarse varias condiciones en una sentencia.
La forma más simple de usar xen:else es algo así como:
Rich (BB code):
<xen:if is="{$forum.node_id} == x">
solo visible en el foro x<xen:else />
TEste contenido se muestra a cualquiera</xen:if>
Rich (BB code):
<xen:if is="{$forum.node_id} == x">
solo visible en el foro x<xen:elseif is="{$forum.node_id} == y" />
solo visible en el foro y<xen:elseif is="{$forum.node_id} == z" />
solo visible en el foro z<xen:else />
Este contenido se muestra a cualquiera</xen:if>
Dependiendo de la plantilla, funcionará o no. Se puede usar $user en vez de $visitor; $visitor siempre es el registro del actual usuario que ha iniciado sesión, $user es el registro que se procesa (ej. autor del mensaje, lista de miembros, lista de usuarios conectados, etc.).
Cuando se trabaja con la plantilla PAGE_CONTAINER, pueden pasarse variables a las plantillas view (category_view, forum_view, thread_view, etc.) usando xen:container. Lo mismo es aplicable a cualquier plantilla incluida en la plantilla PAGE_CONTAINER; la plantilla header o ad_header por ejemplo.
Para usar la variable $forum.node_id por ejemplo, sólo hay que añadir a la plantilla PAGE_CONTAINER: <xen:container var="$forumId">{$forum.node_id}</xen:container>.
Similarmente para la variable $threadId, habrá que añadir: <xen:container var="$threadId">{$thread.thread_id}</xen:container>.
Cuando usamos variables como x, y, o z, deben reemplazarse con sus valores actuales.
How can I show content just to logged in members and hide it from guests?
<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?
<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?
<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?
<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?
<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?
<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?
<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?
<xen:if is="{$visitor.is_admin}">
This content will show to Administrators
</xen:if>How can I show content to Moderators?
<xen:if is="{$visitor.is_moderator}">
This content will show to Moderators
</xen:if>How can I show content to Administrators and Moderators?
<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?
<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?
<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 if the visitor is the user?
<xen:if is="{$visitor.user_id} == {$user.user_id}">
This content will show if the visitor is the user
</xen:if>How can I show content after the first post in a thread?
<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?
<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?
<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?
<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?
<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?
<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?
<xen:if is="{$contentTemplate} == 'xyz'">
This content will show on the xyz template
</xen:if>How can I show content on pages with a sidebar?
<xen:if is="{$sidebar}">
This content will show on pages with a sidebar
</xen:if>How can I show content in a specific category?
<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.
Additionally, to ensure the category ID is available in the ad_ templates, the category_view template must be edited and the following code added: <xen:container var="$category.node_id">{$category.node_id}</xen:container>
How can I show content in a specific forum?
<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?
<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 all forums with a specific parent?
<xen:if is="{$forum.parent_node_id} == x">
This content will show in forums of parent x
</xen:if>How can I show content in a specific thread?
<xen:if is="{$threadId} == x">
This content will show in thread x
</xen:if>How can I show content in more than one thread?
<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?
<xen:if is="{$postId} == x">
This content will show in post x
</xen:if>How can I show content in more than one post?
<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?
<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?
<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?
<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?
<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?
<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 are visible?
<xen:if is="{$user.visible}">
This content will show to members who are visible
</xen:if>How can I show content to members who have an avatar?
<xen:if is="{$visitor.avatar_date} OR {$visitor.gravatar}">
This content will show to members who have an avatar
</xen:if>How can I show content to members who do not have an avatar?
<xen:if is="!{$visitor.avatar_date} AND !{$visitor.gravatar}">
This content will show to members who do not have an avatar
</xen:if>How can I show content to members who have completed a custom user field?
<xen:if is="{$visitor.customFields.field_id}">
This content will show to members who have completed the custom user field
</xen:if>Note that field_id must be replaced with the actual custom user field identifier.
How can I show content to members who have not confirmed their email address?
<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?
<xen:if is="{$visitor.from_search}">
This content will show to visitors arriving from search engines
</xen:if>Sólo visible a miembros:
PHP:
<xen:if is="{$visitor.user_id}"> .......</xen:if>
PHP:
<xen:if is="!{$visitor.user_id}"> .......</xen:if>
PHP:
<xen:if is="{$visitor.is_admin}">.......</xen:if>
PHP:
<xen:if is="{$visitor.is_moderator}"></xen:if>
PHP:
<xen:if is="{$visitor.message_count} < 5">.......</xen:if>
PHP:
<xen:if is="{$visitor.user_group_id} == '2'"> .......</xen:if>
PHP:
<xen:if is="{$visitor.user_group_id} == X OR {$visitor.user_group_id} == Y OR {$visitor.user_group_id} == Z">.......</xen:if>
PHP:
<xen:if is="{$contentTemplate} != 'forum_list'"> .......</xen:if>
PHP:
<xen:if is="{$forum.node_id}==x">.......</xen:if>
PHP:
<xen:if is="{$thread.thread_id}==x">.......</xen:if>
Salud2