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

Reply
 
Thread Tools Display Modes
  #1  
Old 05-05-2011, 05:24 PM
TrigZu TrigZu is offline
 
Join Date: Jul 2010
Posts: 18
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Is passing raw variables from PHP to be parsed by a template possible?

Is passing raw variables from PHP to be parsed by a template possible?

I have this in my PHP page.
PHP Code:
$content "<vb:if condition=\"'1'=='1'\">test<vb:else />not</vb:if>";

vB_Template::preRegister('Web Page',array('content' => $content)); 
And this in my template
Code:
{vb:raw content}
However the vB template conditionals aren't being parsed.

It's just going straight to the web page.
Reply With Quote
  #2  
Old 05-05-2011, 09:09 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Parse the conditions in your php and then just pass the result.
Reply With Quote
  #3  
Old 05-05-2011, 09:13 PM
Disasterpiece's Avatar
Disasterpiece Disasterpiece is offline
 
Join Date: Apr 2007
Location: GER
Posts: 765
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Why would you want to do that? template conditionals is just a cheap method because php isn't available there. Everything you can build with template vars, you can do even better with php.

PHP Code:
if ('1'=='1'$content "test";
else 
$content "not";

vB_Template::preRegister('Web Page',array('content' => $content)); 
Reply With Quote
  #4  
Old 05-05-2011, 09:31 PM
Boofo's Avatar
Boofo Boofo is offline
 
Join Date: Mar 2002
Location: Des Moines, IA (USA)
Posts: 15,776
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Disasterpiece View Post
Why would you want to do that? template conditionals is just a cheap method because php isn't available there. Everything you can build with template vars, you can do even better with php.

PHP Code:
if ('1'=='1'$content "test";
else 
$content "not";

vB_Template::preRegister('Web Page',array('content' => $content)); 
Ahh, so you don't like to use brackets either, huh?


Quote:
Originally Posted by TrigZu View Post
Is passing raw variables from PHP to be parsed by a template possible?

I have this in my PHP page.
PHP Code:
$content "<vb:if condition=\"'1'=='1'\">test<vb:else />not</vb:if>";

vB_Template::preRegister('Web Page',array('content' => $content)); 
And this in my template
Code:
{vb:raw content}
However the vB template conditionals aren't being parsed.

It's just going straight to the web page.

You could always make a template and just pass that in php with a goof ol' str_replace.
Reply With Quote
  #5  
Old 05-05-2011, 10:09 PM
TrigZu TrigZu is offline
 
Join Date: Jul 2010
Posts: 18
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Disasterpiece View Post
Why would you want to do that? template conditionals is just a cheap method because php isn't available there. Everything you can build with template vars, you can do even better with php.

PHP Code:
if ('1'=='1'$content "test";
else 
$content "not";

vB_Template::preRegister('Web Page',array('content' => $content)); 
Yeah, I know. It's just that I already wrote the whole thing in the template and I wanted to put it in the PHP page instead (I didn't plan ahead), but I'm too lazy to go back and change all of the conditionals to PHP statements. I could use some RegEx to do it "quickly", but I'm sure there's some function built into vB to take care of this, so I guess I'll just look for it. =]

Thanks guys.
Reply With Quote
  #6  
Old 05-05-2011, 10:51 PM
Boofo's Avatar
Boofo Boofo is offline
 
Join Date: Mar 2002
Location: Des Moines, IA (USA)
Posts: 15,776
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You first post would never work as vb 4 doesn't recognize the if conditions when you are trying to replace them. There are ways around it but you are not going to find it in the vb documentation, sorry to say.
Reply With Quote
  #7  
Old 05-07-2011, 12:12 AM
Disasterpiece's Avatar
Disasterpiece Disasterpiece is offline
 
Join Date: Apr 2007
Location: GER
Posts: 765
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

well, you could try to find the template functions which do the preprocessing, work with output buffers your way around and ... well that's not only a pain but I'd have to put you in jail if you did that, so I highly recommend to learn from your mistakes and re-program it to php.

Quote:
Ahh, so you don't like to use brackets either, huh?
For 1-2 liners, brackets are useless and blow up the code unnecessarily.

Also, yeah they're uncool.
Reply With Quote
  #8  
Old 05-07-2011, 12:34 AM
Boofo's Avatar
Boofo Boofo is offline
 
Join Date: Mar 2002
Location: Des Moines, IA (USA)
Posts: 15,776
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Disasterpiece View Post
For 1-2 liners, brackets are useless and blow up the code unnecessarily.

Also, yeah they're uncool.
I'm a bracket man, myself. If it is one line, then yes, no brackets are necessary. But if there is an else statement, or more than one line, I always use brackets. The code is a lot easier to read and follow that way. Try putting me in jail for that.
Reply With Quote
  #9  
Old 08-08-2011, 06:45 PM
abdicar abdicar is offline
 
Join Date: Oct 2006
Posts: 22
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

So, there is no way to pass a raw variable to a coditional?
Reply With Quote
  #10  
Old 08-08-2011, 06:54 PM
Disasterpiece's Avatar
Disasterpiece Disasterpiece is offline
 
Join Date: Apr 2007
Location: GER
Posts: 765
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

PHP Code:
vB_Template::preRegister('template_name',array('foo' => $bar));

...

$templater->register('foo'$bar); 
First if you don't create an instance of the template first, second if you already have an instance
like:
PHP Code:
$templater vB_Template::create('template_name');
$templater->register(...) 
Inside the template they exist as $foo so you can write:
HTML Code:
<vb:if condition="$foo == 'bar'">
display this
<vb:else />
otherwise this
</vb:if>
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 04:59 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.04224 seconds
  • Memory Usage 2,274KB
  • Queries Executed 13 (?)
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
  • (2)bbcode_code
  • (1)bbcode_html
  • (7)bbcode_php
  • (5)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)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_postinfo_query
  • fetch_postinfo
  • 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
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete