vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   Templates won't recognize my variables (https://vborg.vbsupport.ru/showthread.php?t=100618)

mutus123 11-11-2005 10:17 PM

Templates won't recognize my variables
 
What am I missing here? All I want to do is add a conditional on FORUMHOME, so that one certain forum does not display regular forum bits, but rather some custom markup. I thought it would be a breeze.

In forumhome_forumbit_level1_nopost, I want to change this
PHP Code:

<tbody id="collapseobj_forumbit_$forumidstyle="{$collapseobj_forumid}">
    
$childforumbits
</tbody

to this
PHP Code:

<tbody id="collapseobj_forumbit_$forumidstyle="{$collapseobj_forumid}">
<if 
condition="$forum[forumid] == 46">
    
$my_custom_var
<else />
    
$childforumbits
</if>
</
tbody

The problem is that no matter where I attempt to define $my_custom_var, the template will never recognize it. I have tried every hook imaginable, and also tried to define it directly in index.php, global.php, and init.php. Nothing works.

I'm sure I have the problem isolated to $my_custom_var because this works as expected...
PHP Code:

<tbody id="collapseobj_forumbit_$forumidstyle="{$collapseobj_forumid}">
<if 
condition="$forum[forumid] == 46">
    Print 
custom text here.
<else />
    
$childforumbits
</if>
</
tbody

In addition, I assigned some custom text to a known recognized variable ($show) and that also works as expected...
PHP Code:

<tbody id="collapseobj_forumbit_$forumidstyle="{$collapseobj_forumid}">
<if 
condition="$forum[forumid] == 46">
    
$show[my_custom_var]
<else />
    
$childforumbits
</if>
</
tbody

Of course, I don't want to, and shouldn't have to dump a big chunk of markup into the $show array. Do I need to register my custom variable somewhere so it gets recognized? Again, I have tried all the hooks, I have tried direct file edits. I have used DEVDEBUG (which annoyingly spits out the expected variable :ermm: ).... yet it just refuses to get recognized by that template. Now I'm aggravated. I been lurking here for years and always found my answers by searching. Aaaaaggghh ;)

Can anyone please fill me in on what I'm missing here?

Marco van Herwaarden 11-12-2005 05:18 AM

Well $show would be the most appropriate place to put it. But try adding a 'global $my_custom_var;' to your script.

mutus123 11-12-2005 10:12 AM

Quote:

Originally Posted by MarcoH64
Well $show would be the most appropriate place to put it. But try adding a 'global $my_custom_var;' to your script.

Thank you, I didn't know that $show would be the appropriate place for it. I'll probably just use that then. :)

Marco van Herwaarden 11-12-2005 10:21 AM

It is good custom to prefix your variables in this kinda places, to avoid possible future problems with Jelsoft variables.

So use:
$post['mutus_myvar']

and not:
$post['myvar']

mutus123 11-12-2005 09:39 PM

Quote:

Originally Posted by MarcoH64
It is good custom to prefix your variables in this kinda places, to avoid possible future problems with Jelsoft variables.

So use:
$post['mutus_myvar']

and not:
$post['myvar']

Thanks again Marco

I do always attempt to uniquely identify any custom variables or function names of my own. I only used $my_custom_var as an example.

My real names I don't think will ever surface in native VB code. :classic:

at least I should hope not... :paranoid: :nervous:

nexialys 11-12-2005 11:49 PM

Quote:

Originally Posted by mutus123
My real names I don't think will ever surface in native VB code. :classic:
at least I should hope not... :paranoid: :nervous:

the point here is that all your variables may not be globalised by vB itself when you call your template, because the call itself is a function, though you need your variables to be known by the function... using the default vbulletin variable arrays is the best way... like $show and $post... because you're sure they will be detected...!

so instead of $yourvariable, use $show[yourvariable] when creating and calling your variables, and you're sure it will be done correctly in a strange situation... :)


All times are GMT. The time now is 07:00 AM.

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.01119 seconds
  • Memory Usage 1,739KB
  • 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
  • (4)bbcode_php_printable
  • (3)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (6)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