E
E
Edward V.2015-03-23 21:22:12
PHP
Edward V., 2015-03-23 21:22:12

Do you need to form and write one condition correctly?

Hello.
There is a forum with two main categories and many subcategories. All this is displayed on one page. And it turns out a big sheet.
Here is the original code:

{foreach from=$aForums item=oForum}
      {if $oForum->getAllowShow()}
        {assign var='aSubForums' value=$oForum->getChildren()}
        <section class="forums-list category-block toggle-section" id="category-{$oForum->getId()}">
          <header class="forums-header well well-sm">
            <i class="js-forum-cat-toggler"></i>
            <h2><a href="{$oForum->getUrlFull()}" title="{$oForum->getTitle()}"><i class="fa fa-folder fa-lg"></i> {$oForum->getTitle()}</a></h2>
          </header>
          <div class="forums-content well">
            {include file="$sTemplatePathForum/forums_list.tpl" aForums=$aSubForums}
          </div>
          <div class="forums-note clearfix" style="display:none;">
            <div class="fl-r">
              <strong>{$oForum->getCountTopic()|number_format:0:'.':$oConfig->Get('plugin.forum.number_format')}</strong> {$oForum->getCountTopic()|declension:$aLang.plugin.forum.topics_declension:'russian'|lower}
              <span>|</span>
              <strong>{$oForum->getCountPost()|number_format:0:'.':$oConfig->Get('plugin.forum.number_format')}</strong> {$oForum->getCountPost()|declension:$aLang.plugin.forum.posts_declension:'russian'|lower}
            </div>
          </div>
        </section>
      {/if}
    {/foreach}

I decided to make changes to the display using tabs, Tabs from Bootstrap ( getbootstrap.com/javascript/#tabs ).
<ul class="nav nav-tabs" id="cat-tab">
      <li class="active"><a href="#category-13" data-toggle="tab">форум_1</a></li>
      <li class=""><a href="#category-11" data-toggle="tab">-форум_2</a></li>
</ul>

 <div class="tab-content">
         {foreach from=$aForums item=oForum}
                   {if $oForum->getAllowShow()}
                             {assign var='aSubForums' value=$oForum->getChildren()}
                       <div class="tab-pane forums-list toggle-section" id="category-{$oForum->getId()}">
                               <header class="forums-header well well-sm">
                                                  <i class="js-forum-cat-toggler"></i>
                                                  <h2><a href="{$oForum->getUrlFull()}" title="{$oForum->getTitle()}"><i class="fa fa-folder fa-lg"></i> {$oForum->getTitle()}</a></h2>
                                        </header>
                                       <div class="forums-content well">
                                                {include file="$sTemplatePathForum/forums_list.tpl" aForums=$aSubForums}
                                       </div>
                                       <div class="forums-note clearfix" style="display:none;">
                                                <div class="fl-r">
                                                         <strong>{$oForum->getCountTopic()|number_format:0:'.':$oConfig->Get('plugin.forum.number_format')}</strong> {$oForum->getCountTopic()|declension:$aLang.plugin.forum.topics_declension:'russian'|lower}
                                                         <span>|</span>
                                                         <strong>{$oForum->getCountPost()|number_format:0:'.':$oConfig->Get('plugin.forum.number_format')}</strong> {$oForum->getCountPost()|declension:$aLang.plugin.forum.posts_declension:'russian'|lower}
                                               </div>
                                       </div>
                     </div>
                  {/if}
            {/foreach}
</div>

The problem is that by default, one of the tabs should immediately have the active class. If you immediately assign, here:
<div class="tab-pane forums-list toggle-section active" id="category-{$oForum->getId()}">

That all tabs are active, all are shown.
In this regard, I ask for help in writing a condition that would assign the active class at the right time?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir Shiklgruber, 2015-03-23
@aaadddminnn

I don't know maybe govnokod. But it is possible, for example

if($_GET['do'] == '1' ){
echo 'ваш текст1';
} else {
echo 'ваш текст2';
}

As a result, if the url is of the form index.php?do=1, then your text1 will be on the screen; if not, then your text2 will initially disable error output. because if the url is of the form index.php it will swear that do is empty.

H
holfza, 2015-03-23
@holfza

Get a counter $count = 1, and at each iteration increase it, for example, by 1.
And so:
<?=($count == 1)?'active':'';

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question