vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   Is passing raw variables from PHP to be parsed by a template possible? (https://vborg.vbsupport.ru/showthread.php?t=263211)

TrigZu 05-05-2011 05:24 PM

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.

Lynne 05-05-2011 09:09 PM

Parse the conditions in your php and then just pass the result.

Disasterpiece 05-05-2011 09:13 PM

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)); 


Boofo 05-05-2011 09:31 PM

Quote:

Originally Posted by Disasterpiece (Post 2192437)
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 (Post 2192346)
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.

TrigZu 05-05-2011 10:09 PM

Quote:

Originally Posted by Disasterpiece (Post 2192437)
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. :D

Boofo 05-05-2011 10:51 PM

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.

Disasterpiece 05-07-2011 12:12 AM

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.

Boofo 05-07-2011 12:34 AM

Quote:

Originally Posted by Disasterpiece (Post 2192821)
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. ;)

abdicar 08-08-2011 06:45 PM

So, there is no way to pass a raw variable to a coditional?

Disasterpiece 08-08-2011 06:54 PM

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>



All times are GMT. The time now is 01:10 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.01204 seconds
  • Memory Usage 1,756KB
  • 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
  • (2)bbcode_code_printable
  • (1)bbcode_html_printable
  • (7)bbcode_php_printable
  • (5)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)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