A little help to hide some categories in forum_list [Conditional inside]

rafass

Member
Hello Friends!
I need a little help to hide certain categories depends of the language selected using this nice conditional:
Code:
<xen:if is="{$visitor.language_id} == x">
Certain Categories / Forums
</xen:if>
In forum_list
Anyone can give me a hand / idea to do this? I've been trying several hours without success.
Appreciate some help. Even I'm willing to pay, if is a little difficult.
Many thanks!​
 
I think you want to do that in these templates..

node_category_level_1
node_category_level_2
node_category_level_n

And I do believe you'll need to add a condition for the node too...
Code:
<xen:if is="{$visitor.language_id} == x && {$category.node_id} == x">
 
Hello Snog! that sound good.
Code:
<xen:require css="node_list.css" />
<xen:require css="node_category.css" />

<li class="node category level_{$level} node_{$category.node_id}" id="{xen:helper linktitle, $category.node_id, $category.title, 1}">

    <div class="nodeInfo categoryNodeInfo categoryStrip">
   
        <div class="categoryText">
            <h3 class="nodeTitle"><a href="{xen:link categories, $category}">{$category.title}</a></h3>
            <xen:if is="{$category.description}"><blockquote class="nodeDescription baseHtml">{xen:raw $category.description}</blockquote></xen:if>
        </div>
       
    </div>
   
    <xen:if is="{$renderedChildren}">       
        <ol class="nodeList">
            <xen:foreach loop="$renderedChildren" value="$child">{xen:raw $child}</xen:foreach>
        </ol>
    </xen:if>
   
    <span class="tlc"></span>
    <span class="trc"></span>
    <span class="blc"></span>
    <span class="brc"></span>
</li>
Code:
<xen:require css="node_list.css" />
<xen:require css="node_category.css" />

<li class="node category_forum level_{$level} node_{$category.node_id}">

    <div class="nodeInfo categoryForumNodeInfo {xen:if $category.hasNew, 'unread'}">

        <span class="nodeIcon" title="{xen:if $category.hasNew, '{xen:phrase unread_messages}', ''}"></span>

        <div class="nodeText">
            <h3 class="nodeTitle"><a href="{xen:link categories, $category}" data-description="{xen:if @nodeListDescriptionTooltips, '#nodeDescription-{$category.node_id}'}">{$category.title}</a></h3>

            <xen:if is="{$category.description} AND @nodeListDescriptions">
                <blockquote class="nodeDescription {xen:if @nodeListDescriptionTooltips, nodeDescriptionTooltip} baseHtml" id="nodeDescription-{$category.node_id}">{xen:raw $category.description}</blockquote>
            </xen:if>

            <div class="nodeStats pairsInline">
                <dl><dt>{xen:phrase discussions}:</dt> <dd>{xen:if $category.privateInfo, '&ndash;', {xen:number $category.discussion_count}}</dd></dl>
                <dl><dt>{xen:phrase messages}:</dt> <dd>{xen:if $category.privateInfo, '&ndash;', {xen:number $category.message_count}}</dd></dl>
                <xen:if is="{$renderedChildren} AND @nodeListSubForumPopup">
                    <div class="Popup subForumsPopup">
                        <a href="{xen:link categories, $category}" rel="Menu" class="cloaked" data-closemenu="true"><span class="dt">{xen:phrase sub_forums}:</span> {xen:number $category.childCount}</a>
                       
                        <div class="Menu JsOnly subForumsMenu">
                            <div class="primaryContent menuHeader">
                                <h3>{$category.title}</h3>
                                <div class="muted">{xen:phrase sub_forums}</div>
                            </div>
                            <ol class="secondaryContent blockLinksList">
                            <xen:foreach loop="$renderedChildren" value="$child">
                                {xen:raw $child}
                            </xen:foreach>
                            </ol>
                        </div>
                    </div>
                </xen:if>
            </div>
           
            {xen:raw $nodeExtraHtml}
        </div>

        <xen:if is="{$renderedChildren} AND !@nodeListSubForumPopup">
            <ol class="subForumList">
            <xen:foreach loop="$renderedChildren" value="$child">
                {xen:raw $child}
            </xen:foreach>
            </ol>
        </xen:if>

        <div class="nodeLastPost secondaryContent">
            <xen:if is="{$category.privateInfo}">
                <span class="noMessages muted">({xen:phrase private})</span>
            <xen:elseif is="{$category.lastPost.date}" />
                <span class="lastThreadTitle"><span>{xen:phrase latest}:</span> <a href="{xen:link posts, $category.lastPost}" title="{$category.lastPost.title}">{$category.lastPost.title}</a></span>
                <span class="lastThreadMeta">
                    <span class="lastThreadUser"><xen:if is="{xen:helper isIgnored, $category.last_post_user_id}">{xen:phrase ignored_member}<xen:else /><xen:username user="$category.lastPost" /></xen:if>,</span>
                    <xen:datetime time="$category.lastPost.date" class="muted lastThreadDate" data-latest="{xen:phrase latest}: " />
                </span>
            <xen:else />
                <span class="noMessages muted">({xen:phrase contains_no_messages})</span>
            </xen:if>
        </div>

    </div>

</li>
Code:
<li class="node category level-n node_{$category.node_id}">
    <div {xen:if $category.hasNew, 'class="unread"'}>
        <h4 class="nodeTitle"><a href="{xen:link categories, $category}" class="menuRow">{$category.title}</a></h4>
    </div>
    <xen:if is="{$renderedChildren}">
        <ol>
            <xen:foreach loop="$renderedChildren" value="$child">
                {xen:raw $child}
            </xen:foreach>
        </ol>
    </xen:if>
</li>

You must validate your XenForo license to see quoted content
That conditional looks really cool! anyway I've working with this with easy and small elements / templates (and works like a charm)
But I'm lost with the templates above.
I have ready my ACP with the categories / languages. if you want to make tests there with this templates. (if you can give me a hand on it)
Appreciate so much your help Snog!
 
You would want to put the if statement before the <li ... and the /xen:if after the </li>

Code:
<xen:require css="node_list.css" />
<xen:require css="node_category.css" />
<xen:if is="{$visitor.language_id} == x && {$category.node_id} == x">
<li class="node category level_{$level} node_{$category.node_id}" id="{xen:helper linktitle, $category.node_id, $category.title, 1}">

   <div class="nodeInfo categoryNodeInfo categoryStrip">

     <div class="categoryText">
       <h3 class="nodeTitle"><a href="{xen:link categories, $category}">{$category.title}</a></h3>
       <xen:if is="{$category.description}"><blockquote class="nodeDescription baseHtml">{xen:raw $category.description}</blockquote></xen:if>
     </div>
  
   </div>

   <xen:if is="{$renderedChildren}">  
     <ol class="nodeList">
       <xen:foreach loop="$renderedChildren" value="$child">{xen:raw $child}</xen:foreach>
     </ol>
   </xen:if>

   <span class="tlc"></span>
   <span class="trc"></span>
   <span class="blc"></span>
   <span class="brc"></span>
</li>
</xen:if>

You can also change the category part to a list of categories by doing this..
Code:
<xen:if is="{$visitor.language_id} == x && in_array({$category.node_id} , array(1,2,3,4,5,etc))">

But I am at a loss as to why you would want to hide categories based on language. I think that's an unwise thing to do. What will unregistered users see? Nothing?
 
Why don't you just use the built in promotion system and add people to a different user group based on their language? Then set the permissions for the forums based on that.
 
Awesome! This is almost done!!
The language #1 (English) are showing only the category #1 (English Zone) that's perfect! :)
Now, how to add the other conditional to the language #2 (Spanish) to show only the category #2 (Spanish Zone) ?
I guess I have to use xen:elseif ? I have this now:
Code:
<xen:if is="{$visitor.language_id} == 1 && {$category.node_id} == 1">
TEMPLATE [Category 1]
</xen:if>
how to include the second conditional there?
Code:
<xen:if is="{$visitor.language_id} == 2 && {$category.node_id} == 2">
TEMPLATE [Category 2]
</xen:if>
--
Regarding the questions:
You must validate your XenForo license to see quoted content
Because each category will contain forums in a specific language.

English Zone [Category]
---English 1 [Forum]
---English 2 [Forum]
Spanish Zone [Category]
---Spanish 1 [Forum]
---Spanish 2 [Forum]

So, depending of the language selected you will see only the that specific language. if you know other languages and you want to take a look at these categories, just have to switch the language. :)

You must validate your XenForo license to see quoted content
The system of user promotions has been discarded for various reasons many days ago.

This new way is absolutely fantastic! I'll show you the result and you will see ;)
 
Don't use the else, I think an OR (||) will work.

Code:
<xen:if is="({$visitor.language_id} == 1 && {$category.node_id} == 1) || ({$visitor.language_id} == 2 && {$category.node_id} == 2)">
 
Hello Snog! Your conditional works like a charm, I'm very happy with the result. :D

Now I'm using only 2 languages:
#1 English
#2 Spanish

With 2 categories
#1 English Category
#2 Spanish Category

Rich (BB code):
<xen:if is="({$visitor.language_id} == 1 && {$category.node_id} == 1) || ({$visitor.language_id} == 2 && {$category.node_id} == 2)">
node_category_level_1 TEMPLATE 
</xen:if>
This is absolutely perfect ↑↑ :)

--

But If in the future I want to include the languages:
#3 French
#4 Italian
#5 German

And the categories
#3 French Category
#4 Italian Category
#5 German Category

I can do this?

Rich (BB code):
<xen:if is="({$visitor.language_id} == 1 && {$category.node_id} == 1) || ({$visitor.language_id} == 2 && {$category.node_id} == 2) || ({$visitor.language_id} == 3 && {$category.node_id} == 3) || ({$visitor.language_id} == 4 && {$category.node_id} == 4) || ({$visitor.language_id} == 5 && {$category.node_id} == 5)">
node_category_level_1 TEMPLATE 
</xen:if>

Or I have to replace (||) and use another instead?

Many Thanks again!
 
The way you have it should work. You should be able to expand it out to as many languages as you want.
 
Hello Snog, I would like to do the same on resource_choose_category XenForo Resource Manager
Depends of the language selected, show certain categories on yoursite/resources/add/
This is the template:
You must validate your XenForo license to see quoted content
As you can see, the categories on the option are controlled by the red code. (maybe?)
anyway, I've been trying to edit the template on many ways with the conditional we use above. but still can not find the way to make this work.
If you can give me a hand I'll appreciate it so much.
 
Here you go...

Rich (BB code):
<xen:title>{xen:phrase choose_category}</xen:title>

<form action="{xen:link 'resources/add'}" method="post" class="xenForm formOverlay">

   <dl class="ctrlUnit">
     <dt><label for="ctrl_resource_category_id">{xen:phrase category}:</label></dt>
     <dd>
       <select name="resource_category_id" class="textCtrl" id="ctrl_resource_category_id" autofocus="true">
         <option value="0">&nbsp;</option>
         <xen:foreach loop="$categories" key="$categoryId" value="$_category">
         <xen:if is="({$visitor.language_id} == 1 && {$categoryId} == 2)">
           <option value="{$categoryId}"
             {xen:if '!{$_category.allowResource} or !{$_category.canAdd}', 'disabled="disabled"'}
             >{xen:string repeat, '&nbsp; ', $_category.depth}{$_category.category_title}</option>
         </xen:if>
         </xen:foreach>
       </select>
       <p class="explain">{xen:phrase select_category_that_best_describes_your_resource}</p>
     </dd>
   </dl>

   <dl class="ctrlUnit submitUnit">
     <dt></dt>
     <dd>
       <input type="submit" value="{xen:phrase continue}..." accesskey="s" class="button primary" />
     </dd>
   </dl>

   <input type="hidden" name="_xfToken" value="{$visitor.csrf_token_page}" />
</form>


Expand the if statement just like the other template for each language and category ID.
 
Very nice! ^ . ^ thank you so much! my mistake: I was not using $categoryId :D
To my own references, and maybe can help someone, here my resource_choose_category
Rich (BB code):
<xen:title>{xen:phrase choose_category}</xen:title>

<form action="{xen:link 'resources/add'}" method="post" class="xenForm formOverlay">

   <dl class="ctrlUnit">
     <dt><label for="ctrl_resource_category_id">{xen:phrase category}:</label></dt>
     <dd>
       <select name="resource_category_id" class="textCtrl" id="ctrl_resource_category_id" autofocus="true">
         <option value="0">&nbsp;</option>
         <xen:foreach loop="$categories" key="$categoryId" value="$_category">
     
         <xen:if is="(!{$visitor.language_id} && in_array({$category.id} , array(1,2)) || 
           {$visitor.language_id} == 1 && in_array({$categoryId} , array(1,2)) || 
           {$visitor.language_id} == 2 && in_array({$categoryId} , array(3,4)) || 
           {$visitor.language_id} == 3 && in_array({$categoryId} , array(5,6)) ">
           <option value="{$categoryId}"
             {xen:if '!{$_category.allowResource} or !{$_category.canAdd}', 'disabled="disabled"'}
             >{xen:string repeat, '&nbsp; ', $_category.depth}{$_category.category_title}</option>
         </xen:if>
     
         </xen:foreach>
       </select>
       <p class="explain">{xen:phrase select_category_that_best_describes_your_resource}</p>
     </dd>
   </dl>

   <dl class="ctrlUnit submitUnit">
     <dt></dt>
     <dd>
       <input type="submit" value="{xen:phrase continue}..." accesskey="s" class="button primary" />
     </dd>
   </dl>

   <input type="hidden" name="_xfToken" value="{$visitor.csrf_token_page}" />
</form>
Works absolutely perfect! ;)
 
Back
Top