Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 09-01-2004, 06:38 PM
Ocean's Avatar
Ocean Ocean is offline
 
Join Date: Mar 2004
Posts: 208
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default I need help with an IF conditional...

Okay, here's the scenario - I have a section of code in one of the PHP files that sets a variable to either true or false, for example:


PHP Code:
 
if (blah blah blah)
{
 
$custom_variable true;
 
}
 
 
else
{
 
$custom_variable false;
 


Now, I want a section in one of the vB Templates to be able to pull from that so that if $custom_variable was set to true, than a section of code would execute (and if it's false, it would not) - for example:


Code:
 
<if condition="$custom_variable">
 
<!-- Insert Code to be executed here -->
 
</if>

However, the template portion of the code isn't working for me.

So the question is - what am I doing wrong?
Reply With Quote
  #2  
Old 09-01-2004, 07:18 PM
rake's Avatar
rake rake is offline
 
Join Date: Nov 2002
Posts: 311
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

What you've done seems fine, but keep in mind you can't "execute" any code in the templates. It's plain html that goes there, besides the variables and the conditional system.
Reply With Quote
  #3  
Old 09-01-2004, 10:34 PM
Ocean's Avatar
Ocean Ocean is offline
 
Join Date: Mar 2004
Posts: 208
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by rake

What you've done seems fine, but keep in mind you can't "execute" any code in the templates. It's plain html that goes there, besides the variables and the conditional system.
That's fine - the code that gets inserted there is standard Template-style code. The problem is that that code is being run, even though the template IF statement should be evaluating to false.

Is the problem that the variable in the PHP code needs to be defined or declared previously?


Because either there is a problem with that variable, or the template IF statement can't read it properly.
Reply With Quote
  #4  
Old 09-02-2004, 02:03 AM
CarCdr CarCdr is offline
 
Join Date: Apr 2004
Posts: 242
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by rake
What you've done seems fine, but keep in mind you can't "execute" any code in the templates. It's plain html that goes there, besides the variables and the conditional system.
While not really on subject for Ocean, I believe you can execute code in a template conditional. For example, the following should work:

<if condition="$FOO==1 AND $FOO = 2">

would set $FOO to 2 if it was equal to 1. I would bet one can hide any PHP one wanted in conditionals, with just a little trickery.
Reply With Quote
  #5  
Old 09-02-2004, 09:54 AM
rake's Avatar
rake rake is offline
 
Join Date: Nov 2002
Posts: 311
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

CarCdr,
i was referring to the "Insert Code to be executed here" part of his statement, which is between if tags.

Ocean, is the variable defined BEFORE the template is evaluated? Also, check it's value by just adding
echo $custom_variable; exit;
after the if.
Reply With Quote
  #6  
Old 09-02-2004, 11:22 AM
nexialys
Guest
 
Posts: n/a
Default

work this out with the vB iif:
PHP Code:
$custom_variable iif('blah blah'1); 
with that, your $custom_variable will have a value, then be parsed within the
PHP Code:
<if condition="$custom_variable"></if> 
Reply With Quote
  #7  
Old 09-02-2004, 11:57 AM
Ocean's Avatar
Ocean Ocean is offline
 
Join Date: Mar 2004
Posts: 208
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Okay, problem solved. My original code should have worked just fine - the text editor I happened to use once added an additional hidden character to a Paste function, which effectively made it so that the variable being set in the PHP file was not the same variable being called by the template code.


I hate it when problems of this nature surface. Ai.

Thank you, everyone, for your help.
Reply With Quote
  #8  
Old 09-02-2004, 12:08 PM
rake's Avatar
rake rake is offline
 
Join Date: Nov 2002
Posts: 311
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

That's why notepad rocks.
Reply With Quote
  #9  
Old 09-02-2004, 12:15 PM
Ocean's Avatar
Ocean Ocean is offline
 
Join Date: Mar 2004
Posts: 208
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by rake

That's why notepad rocks.
Actually, my usual Text Editor of choice is UltraEdit, and it makes Notepad look like a slab of rock with a hammer and chisel.

It's the one time I deviated from that, that I got burned. Well, that will be the last time that happens.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 02:15 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04345 seconds
  • Memory Usage 2,243KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)bbcode_code
  • (3)bbcode_php
  • (3)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (9)post_thanks_box
  • (9)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (9)post_thanks_postbit_info
  • (9)postbit
  • (8)postbit_onlinestatus
  • (9)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.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
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete