vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   How to use compile_template function? (https://vborg.vbsupport.ru/showthread.php?t=263310)

EWGF 05-08-2011 12:43 AM

How to use compile_template function?
 
I want to parse conditions with a custom databasetable, so according to vb.com I need to use the compile_template() function.

Code:

/**
* Processes a raw template for conditionals, phrases etc into PHP code for eval()
*
* @param        string        Template
*
* @return        string
*/
function compile_template($template, &$errors = array())

Besides including adminfunctions_template.php, I have NO idea how to use this in a .php file. Does anyone here know how to use this function?

Boofo 05-08-2011 12:45 AM

I do on vb 4.

EWGF 05-09-2011 12:15 PM

I've looked through some mods here on vb.org. Is it true you can only parse specific specified condition codes and not the template where you want to parse every possible code?

kh99 05-09-2011 12:30 PM

I'm not sure what you're asking. There is a set of php functions that you are allowed to use in an if condtion, if that's what you mean. Are you saying you want to compile a template without that restriction?

EWGF 05-09-2011 01:48 PM

Yes. I have made a simple cms -for outside the forum directory- with some custom tables, but the content in those custom tables can't use conditions and other php functions (the codes show up unparsed in the HTML output). According to vb.com I need to use the compile_template() function for this to work and I'm having trouble to get this function working.

Database content:
PHP Code:

<if condition="$show[member]">Not viewable for guests</if> 

HTML output getting unparsed:
PHP Code:

<if condition="$show[member]">Not viewable for guests</if> 


kh99 05-09-2011 02:11 PM

I did this short test by creating a plugin using hook misc_start:

Code:

if ($_REQUEST['do'] == 'compile')
{
    require_once("includes/adminfunctions_template.php");
    $template = '<if condition="$show[member]">Not viewable for guests</if>';
    echo compile_template($template);
    exit;
}


and the result is:

Code:

".(($show[member]) ? ("Not viewable for guests") : (""))."

so it seems like it's working, although I'm not sure how you're supposed to deal with the dots at the beginning and end, I guess when the function is used there are other strings added to the beginning and end.

Anyway, are you using the return value of compile_template()? I don't think it changes the parameter you pass.

EWGF 05-09-2011 09:12 PM

Yes. I also tried echoing and evaling the db->query or the template name.

But seeing your short test, it's not possible to process the custom db as a vBulletin template? If not, I might be able to wrap it up with some custom templates.

kh99 05-09-2011 09:24 PM

Sorry, I don't really understand what you are asking.

But in case it helps, I played with it a little more and got this:

Code:

if ($_REQUEST['do'] == 'compile')
{
    require_once("includes/adminfunctions_template.php");
    $show[member] = true;
    $template = '<if condition="$show[member]">Not viewable for guests</if>';
    eval ('$output = "' . compile_template($template) . '";');
    echo $output;
    exit;
}


and the output is

Code:

Not viewable for guests

but maybe this has nothing to do with your problem.

Boofo 05-09-2011 09:38 PM

Take a look at this mod. Bob uses compile_template for search and replace.

https://vborg.vbsupport.ru/misc.php?...mcategoryicons

EWGF 05-11-2011 05:57 PM

Thanks, I will look in it
Quote:

Originally Posted by kh99 (Post 2193807)
Sorry, I don't really understand what you are asking.

But in case it helps, I played with it a little more and got this:

Code:

if ($_REQUEST['do'] == 'compile')
{
    require_once("includes/adminfunctions_template.php");
    $show[member] = true;
    $template = '<if condition="$show[member]">Not viewable for guests</if>';
    eval ('$output = "' . compile_template($template) . '";');
    echo $output;
    exit;
}


and the output is

Code:

Not viewable for guests

but maybe this has nothing to do with your problem.

I tested it too, it doesn't work correct with an else statement though

PHP Code:

<if condition="$show[member]">Not viewable for guests<else />Not viewable for members</if> 

HTML Code:

Not viewable for guestsNot viewable for members
I'm afraid there's no way in parsing a custom made database table as if it were a vB template


All times are GMT. The time now is 12:23 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.02055 seconds
  • Memory Usage 1,748KB
  • 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
  • (7)bbcode_code_printable
  • (1)bbcode_html_printable
  • (3)bbcode_php_printable
  • (1)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