vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   I need help with an IF conditional... (https://vborg.vbsupport.ru/showthread.php?t=68972)

Ocean 09-01-2004 05:38 PM

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? :rolleyes:

rake 09-01-2004 06:18 PM

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.

Ocean 09-01-2004 09:34 PM

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.

CarCdr 09-02-2004 01:03 AM

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.

rake 09-02-2004 08:54 AM

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.

nexialys 09-02-2004 10:22 AM

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> 


Ocean 09-02-2004 10:57 AM

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. :)

rake 09-02-2004 11:08 AM

That's why notepad rocks. :D

Ocean 09-02-2004 11:15 AM

Quote:

Originally Posted by rake

That's why notepad rocks. :D

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. :)


All times are GMT. The time now is 06:29 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.02312 seconds
  • Memory Usage 1,734KB
  • 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
  • (1)bbcode_code_printable
  • (3)bbcode_php_printable
  • (3)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (9)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
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete