vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 4 Articles (https://vborg.vbsupport.ru/forumdisplay.php?f=242)
-   -   vB4 Template Conditionals List (https://vborg.vbsupport.ru/showthread.php?t=231525)

BBR-APBT 12-28-2009 10:00 PM

vB4 Template Conditionals List
 
I put this together because it seems lots of people are having problems with the new syntax for conditionals.

First off remember you can not use {vb:raw var} in template conditionals.

Show only members:
Code:

<vb:if condition="$show['member']">Show this to members only</vb:if>

Show only guest:
Code:

<vb:if condition="$show['guest']">Show this to guest only</vb:if>

Show specific user groups :
Code:

<vb:if condition="is_member_of($bbuserinfo, 1,2,3)">Show this to user group 1, 2, and 3</vb:if>

Show one member:
Code:

<vb:if condition="$bbuserinfo['userid'] == 318713">Show this only to the member with the user id of 318713</vb:if>

Show every one but one member:
Code:

<vb:if condition="$bbuserinfo['userid'] != 318713">Show this to every one but the member with the user id of 318713</vb:if>

Show only moderators of any forum:
Code:

<vb:if condition="can_moderate()">Show this to all moderators</vb:if>
Show Moderator of one forum: Remember to change x
Code:

<vb:if condition="can_moderate($forum['x])">Show this if moderator is moderator of the forum with the id of x</vb:if>

Show Moderator of current forum:
Code:

<vb:if condition="can_moderate($forum['forumid'])">Show this to the moderator of the current forum</vb:if>

Show in one forum: Remember to change x
Code:

<vb:if condition="$forum[forumid] == x">Show this if forum id is x</vb:if>

Show is every forum but one: Remember to change x
Code:

<vb:if condition="$forum[forumid] != x">Show this if forum id is not x</vb:if>

Show in several forums:
Code:

<vb:if condition="in_array($forum['forumid'], array(1,2,3))">Show this to forum 1, 2 and 3</vb:if>

Show in only one file: Look for define('THIS_SCRIPT', 'calendar'); in the top of the php file you want it to show in.
Code:

<vb:if condition="THIS_SCRIPT == 'calendar'">Show this only on calendar.php</vb:if>

Show in every file but one: Look for define('THIS_SCRIPT', 'calendar'); in the top of the php file you do not want it to show in.
Code:

<vb:if condition="THIS_SCRIPT != 'calendar'">Show this only on calendar.php</vb:if>

If $customvar is set:
Code:

<vb:if condition="$customvar">Show this if $customvar is set</vb:if>

If $customvar equals:
Code:

<vb:if condition="$customvar == blah">Show this if $customvar equals blah</vb:if>

If $customvar does not equal:
Code:

<vb:if condition="$customvar != blah">Show this if $customvar does not equal blah</vb:if>

vBulletin else statement:
Code:

<vb:if condition="$show['guest']">
Show this to only guest.
<vb:else />
Show this to all registered users
</vb:if>


vBulletin else if statement:
Code:

<vb:if condition="$show['guest']">
Show this to only guest.

<vb:elseif condition="is_member_of($bbuserinfo, 5,6)" />
Show this to user group 5 and 6 which is  mods and admins

<vb:else />
Show this to all registered users

</vb:if>


This is all that I can think of right now off the top of my head.
Please feel free to add any I forgot and I will add them to this list and give you credit.

nubian 12-29-2009 06:30 AM

subscribed!

Antyrael 12-29-2009 01:34 PM

Thanks for this list! :)

Asterix_ita 12-30-2009 07:26 AM

Excuse me a question, to the undersigned not work conditions with $forum[forumid] is the variable that changed?

thanks

PS example

<vb:if condition="!in_array($forum[forumid], array(18,19))">

text text

</vb:if>

Hornstar 12-31-2009 04:31 AM

very nice, this has helped me understand all the conditionals much better.

Hasanudin 12-31-2009 09:13 AM

subscribe too..

nice, thx u

nymyth 12-31-2009 12:10 PM

this is so clutch...nice

rbc 12-31-2009 06:37 PM

super, thanks & happy new yeahr ;)

baghdad4ever 01-01-2010 06:38 AM

thank you very much

ragtek 01-01-2010 08:23 AM

Quote:

Originally Posted by Asterix_ita (Post 1942260)
Excuse me a question, to the undersigned not work conditions with $forum[forumid] is the variable that changed?

thanks


PS example

<vb:if condition="!in_array($forum[forumid], array(18,19))">

text text

</vb:if>

$forum[forumid] have to be registered to the template.
There's an other article here.

Asterix_ita 01-01-2010 08:37 AM

Quote:

Originally Posted by ragtek (Post 1943831)
$forum[forumid] have to be registered to the template.
There's an other article here.

thanks, I must enter the new logic. Happy New Year

MikeWarner 01-02-2010 10:27 AM

Hi - thanks for this post, however, can you provide conditionals for CMS sections please?

BBR-APBT 01-02-2010 02:19 PM

Quote:

Originally Posted by MikeWarner (Post 1944821)
Hi - thanks for this post, however, can you provide conditionals for CMS sections please?

I don't have the CMS and most of these will work for the CMS.

You may have to preregister the var.

abumohamed 01-05-2010 05:44 PM

Thanks

hochun 01-05-2010 10:14 PM

Hello everybody! I have one problem with porting one of my products to VB4.

I have the setting for a product called vfsms_can_stick_by_sms - it's comma separated list of forum-sections where this product is turned on.

In this product I have the following plugin:

Code:

        <plugin active="1" executionorder="5">
            <title>Detecting can thread in this forum can be stick up by SMS or not.</title>
            <hookname>showthread_start</hookname>
            <phpcode>
                <![CDATA[
                    $vfsms_can_stick_by_sms_forums_ids = str_replace(' ', '', $vbulletin->options['vfsms_can_stick_by_sms']);
                    $vfsms_allowed4sticky_forums = explode(',', $vfsms_can_stick_by_sms_forums_ids);
                    // I've already read article from this forum abt passing variables to the template engine
                    vB_Template::preRegister('SHOWTHREAD', array('vfsms_allowed4sticky_forums' => $vfsms_allowed4sticky_forums));
                ]]>
            </phpcode>
        </plugin>

And in template SHOWTHREAD I have next conditional:

Code:

{vb:raw $vfsms_allowed4sticky_forums}
{vb:raw $forumid}

    <table cellpadding="0" cellspacing="0" border="0" width="100%" style="margin:10px">
      <tr>
        <td align="center">

<vb:if condition="$vbulletin->userinfo['userid'] == $threadinfo['postuserid']  AND ($threadinfo['sticky_till'] != '0000-00-00 00:00:00' AND $threadinfo['sticky'] == 1)">
          Your thread is sticky untill <b style="color: red;">{vb:raw threadinfo.sticky_till}</b>!<br />
          For prolongation send sms with the text <b style="color: red;">#vf sticky {vb:raw threadinfo.threadid}</b> to the number <b style="color: blue;">{$vbulletin->options[vfsms_sticky_num]}</b>.

<vb:elseif condition="$vbulletin->userinfo['userid'] == $threadinfo['postuserid']  AND $threadinfo['sticky_till'] == '0000-00-00 00:00:00' AND $threadinfo['sticky'] == 0 AND in_array($forumid, $vfsms_allowed4sticky_forums)" />

          You can make your topic sticky by sending SMS with text <b style="color: red;">#vf sticky {vb:raw threadinfo.threadid}</b> to the number <b style="color: blue;">{$vbulletin->options[vfsms_sticky_num]}</b>.

<vb:else />
    You can not make your topic sticky.
</vb:if>
        </td>
      </tr>
    </table>

I have few problems:

1. variable $vfsms_allowed4sticky_forums can be accessed only as a {vb:raw vfsms_allowed4sticky_forums} and I can not put it to the condition
2. variable $forumid is not accessible anymore

Please, somebody, help me!

--------------- Added [DATE]1262737717[/DATE] at [TIME]1262737717[/TIME] ---------------

but everything is ok if I pass variable directly from the showthread.php:


Code:

1. find showthread.php:2228 print_output($templater->render());
2. replace on

       
Code:

       
        $vfsms_can_stick_by_sms_forums_ids = str_replace(' ', '', $vbulletin->options['vfsms_can_stick_by_sms']);
    $vfsms_allowed4sticky_forums = explode(',', $vfsms_can_stick_by_sms_forums_ids);
        $templater->register('vfsms_allowed4sticky_forums', $vfsms_allowed4sticky_forums);
print_output($templater->render());



and in template also replace $forumid on $thread[forumid]

This is absolutely wrong way of doing the thing I need, pls tell me how to do it without changes in showthread.php!

BBR-APBT 01-07-2010 09:12 PM

well first off this is a thread for conditionals. Thats why your not getting much help with your whole script.

Do you have a conditional specific question? If not please start a new thread and do not hijack this one.

SledgeHead 01-08-2010 04:03 AM

How would I make it so a profile option could disable a toolbar? To be more specific I am trying to make Tweetboard and Wibiya Toolbars optional via user options.

BBR-APBT 01-08-2010 04:53 PM

Quote:

Originally Posted by SledgeHead (Post 1950116)
How would I make it so a profile option could disable a toolbar? To be more specific I am trying to make Tweetboard and Wibiya Toolbars optional via user options.

Do you have a conditional specific question? If not please start a new thread and do not hijack this one.

putuajun 01-08-2010 05:55 PM

subscribed :)

SledgeHead 01-08-2010 07:11 PM

Quote:

Originally Posted by BBR-APBT (Post 1950504)
Do you have a conditional specific question? If not please start a new thread and do not hijack this one.

I apologize. I was wondering for the conditional tags to use to accomplish this.

BBR-APBT 01-09-2010 01:15 AM

Quote:

Originally Posted by SledgeHead (Post 1950619)
I apologize. I was wondering for the conditional tags to use to accomplish this.

You will need more then a conditional to accomplish this.

SledgeHead 01-09-2010 03:07 AM

Right. From my understanding you make a custom profile field and then incorporate they field number into the conditional. No?

BBR-APBT 01-09-2010 03:19 AM

you may have to also register variables depending where you want to put it.


Code:

<vb:if condition="$bbuserinfo['fieldx']">

</vb:if>


abdicar 01-11-2010 05:30 PM

I want to setup an alias for my forum, for the porn forum. So, how I can show that forum, ONLY if the people is accessing using the alias domain name?

In PHP It is easy, but i don't know how can be possible now in vB.

Adam H 01-14-2010 09:05 PM

I could actually kiss you , great list was waiting for some one to get a list done like this.

BBR-APBT 01-15-2010 03:01 AM

Quote:

Originally Posted by riverwire (Post 1955983)
I could actually kiss you , great list was waiting for some one to get a list done like this.

I at least hope your a female. ;)

TimberFloorAu 01-18-2010 09:23 PM

Brilliant list mate :up:

Really helps, keep up the great work. Ste

RL714 01-22-2010 11:10 PM

Useful for adding a advertisement or other information after the first post on every page.

Code:

<vb:if condition="!$GLOBALS['FIRSTPOSTID']"></vb:if>

huuquynh 01-23-2010 04:08 PM

I want to use condition with the custom field. For example, I use custom field number 6 for private information, and I want the member can view it but hide it for everyone.

Is there any example?

3DUInc 01-26-2010 12:49 AM

Excellent thank you very much :)

RL714 01-26-2010 08:51 PM

Quote:

Originally Posted by huuquynh (Post 1964520)
I want to use condition with the custom field. For example, I use custom field number 6 for private information, and I want the member can view it but hide it for everyone.

Is there any example?

you can use this line to show only register user
Quote:

<vb:if condition="$show['member']">Show this to members only</vb:if>

huuquynh 01-27-2010 04:11 PM

Quote:

Originally Posted by RL714 (Post 1967429)
you can use this line to show only register user

sorry for my bad english. I mean the private information is showed for him only, the other members can not see it.

the condition you give is for every member... it can not be used in this case.

RL714 01-29-2010 10:50 PM

Quote:

Originally Posted by huuquynh (Post 1968107)
sorry for my bad english. I mean the private information is showed for him only, the other members can not see it.

the condition you give is for every member... it can not be used in this case.

this the one you're looking for huuquynh, replace the user id

Quote:

<vb:if condition="$bbuserinfo['userid'] == 318713">Show this only to the member with the user id of 318713</vb:if>

huuquynh 01-30-2010 02:36 PM

Hi RL714,

I think your code is right. But this is not simple likes that, because it is not for only a member or owner site. I mean the number 318713 is the dynamic number, it is exactly userid in custom field table. So if condition is: $bbuserinfo['userid'] is exactly his userid, so he can see the value. But if the other member can not see.

For example: you can see your custom field number 6, but I can not see it. And vice versa, I can see my custom field number 6, but you can not see mine.

sadiq6210 01-30-2010 06:17 PM

Thanks :)

Veer 01-30-2010 10:56 PM

Thank you for the article.

Please guide me in converting this to vb4:
Code:

<if condition="is_array($NewestMap)">
and this one too please:
Code:

{$map_page}
{$NewestMap['m_image']}


egyptsons 02-01-2010 11:24 PM

Thanks for your article

I want to add advertisement after the first post in some special forums
so I edit the "ad_showthread_firstpost" Template and add this

Code:

<vb:if condition="in_array($forum['forumid'], array(1,2,3))">Show this to forum 1, 2 and 3</vb:if>
But nothing change in the special forums and the ads not appear

also if I used this
Code:

<vb:if  condition="!in_array($forum[forumid], array(1,2,3))">Show this to forum 1, 2 and 3</vb:if>
it's appear in all forums not only the special (1,2,3)

Can you advice me plz ?

Best regards

fly 02-02-2010 08:29 PM

Hoping someone can help...

I'm trying to convert this template conditional (in threadbit, I'm guessing it matters)...

Code:

<if condition="! $ignore[ $thread['postuserid'] ]">
Using the guide here, I know it should look like this, but it doesn't work:

Code:

<vb:if condition="!$ignore[$thread['postuserid']]">
Could it be that the $ignore variable isn't available in that template? I've seen mention of that in other articles here, I think.

isurua 02-03-2010 03:52 AM

Anyone know a way of getting this to work?

Code:

<vb:if condition='"{vb:raw title}" == "The Latest"'><p>ME</p></vb:if>
{vb:raw title} returns The Latest exactly as I would expect when put into the style but for some reason it may not be working inside a conditional statement. =\

fly 02-03-2010 09:21 AM

Quote:

Originally Posted by isurua (Post 1973651)
Anyone know a way of getting this to work?

Code:

<vb:if condition='"{vb:raw title}" == "The Latest"'><p>ME</p></vb:if>
{vb:raw title} returns The Latest exactly as I would expect when put into the style but for some reason it may not be working inside a conditional statement. =\

Quote:

Originally Posted by from first post
First off remember you can not use {vb:raw var} in template conditionals.

that


All times are GMT. The time now is 08:37 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01851 seconds
  • Memory Usage 1,850KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (32)bbcode_code_printable
  • (14)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)pagenav_pagelink
  • (1)pagenav_pagelinkrel
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (40)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete