PDA

View Full Version : vb4 custom template problem


vsforums
02-07-2014, 02:15 PM
Hi,

I want to use misc.php file to display my custom template.
Example:
misc.php?do=page&template=my_template

And everything works fine except that I cannot find a way to eval my own variable which is inside that template = {vb:raw HTML}

All other vars such as {vb:raw header} and {vb:raw footer} looks okay.

I tried to use parse_template hook to do something like:
global $HTML;

$HTML = "test";

But still HTML is null.

Any idea?

cellarius
02-07-2014, 02:22 PM
$global HTML;
That's not valid PHP.

Anyway, like for any other template, you need to properly register your variables for use in the template. I did an article on that: https://vborg.vbsupport.ru/showthread.php?t=228078

vsforums
02-07-2014, 02:39 PM
I shouldn't have to do it. All that is in misc.php file. One thing that it is missing, is how to eval vars in custom templates. I'm sure there must be a way to do it.

kh99
02-07-2014, 02:50 PM
Well, the misc.php code creates the template, registers some standard variables to it, then renders it, but if you're trying to use other variables then you need to deal with that. You could try using {vb:raw GLOBALS.HTML}, but if that doesn't work you could use vB_Template::preRegister() where $HTML is created, like:


$HTML = "test";
vB_Template::preRegsiter('my_template', array('HTML' => $HTML));

cellarius
02-07-2014, 02:57 PM
I shouldn't have to do it. All that is in misc.php file. One thing that it is missing, is how to eval vars in custom templates. I'm sure there must be a way to do it.
And exactly that way is described in my article. *shrug*

vsforums
02-07-2014, 04:12 PM
And exactly that way is described in my article. *shrug*

I didn't see anything about GLOBALS in your article and that is what worked here :)

Thx guys for help.

cellarius
02-07-2014, 04:52 PM
Making a dirty global trick is not a solution, but a workaround. Of course, I thought you were looking for the correct way to do it in vB. Clearly my mistake, sorry.

kh99
02-07-2014, 05:15 PM
Making a dirty global trick is not a solution, but a workaround. Of course, I thought you were looking for the correct way to do it in vB. Clearly my mistake, sorry.

Yes, you have a point. I don't see any real problem with using GLOBALS that way for something "quick and dirty", but it's probably a good idea to point out that it's not the intended way of doing things, and if you're doing any substantial amount of coding with templates you would want to learn how to register variables. And a good way to do that is to study the article mentioned above.

cellarius
02-07-2014, 06:04 PM
BTW, quick and dirty is what I meant above - dirty alone does not catch it. Sorry, english is not my mother tongue ;)

vsforums
02-07-2014, 07:23 PM
Making a dirty global trick is not a solution, but a workaround. Of course, I thought you were looking for the correct way to do it in vB. Clearly my mistake, sorry.

You are right. I've reviewed and tested both options and I went with preRegister one ;)

Thx again.