PDA

View Full Version : parsing and fetching template


Dr.CustUmz
03-03-2015, 02:14 PM
ive done this a million times before but for some reason this isnt working, ive uninstalled the product reinstalled it but i cant fetch my template and its urkin me -_-
this is the snippit:
<template name="my_unique_tmplt" templatetype="template" date="0" username="DrCustUmz" version="1.0"><![CDATA[
SOME SHIT
]]></template>
</templates>
<plugins>
<plugin active="1" executionorder="5">
<title>cache template</title>
<hookname>cache_templates</hookname>
<phpcode><![CDATA[
$globaltemplates = array_merge($globaltemplates, array('my_unique_tmplt'));
]]></phpcode>
</plugin>
<plugin active="1" executionorder="5">
<title>parse template</title>
<hookname>parse_templates</hookname>
<phpcode><![CDATA[
eval('$someVariable = "' . fetch_template('my_unique_tmplt') . '";');
]]></phpcode>
</plugin>

and in postbit i added:

Variable: $someVariable

but it wont show is there a certain way you have to cache the template for calling it in the postbit?

kh99
03-03-2015, 02:19 PM
Try changing the hook for the second plugin to postbit_display_complete. I believe the problem is that you're creating a globla variable called $someVariable, but the postbit template is evaled in a function, so your global isn't available.

I suppose another fix would be to use $GLOBALS['someVariable'] in the template. That would keep it from executing your plugin for every postbit.

Or you could make an additional plugin using hook postbit_display_complete that just had a global statement in it.

Dr.CustUmz
03-03-2015, 02:25 PM
thanks Kev, you always come through, I used "postbit_display_complete" hook and it works, but you were saying use global to prevent it from running every postbit? the varible will eventually be wrapped in an if condition, and needs to execute if post userid is w/e so should i be ok using it for every postbit?

kh99
03-03-2015, 02:34 PM
If it's just a template then it's not that big of a deal. But if it's always the same for the viewing user (doesn't use anything from the post) then it would be best to just have it eval once. There are a number of ways you could accomplish that. You could use hook postbit_display_complete but use a "global" statement and only eval it if the variable isn't set, or something like that.

Dr.CustUmz
03-03-2015, 02:40 PM
yeah its different for each post the actual template will contain
./$vboptions[drcpo_sup_pb_img_dir]/$post[userid].$post[pbext]
grabbing that posters data
and the variable would be used as the img src, its for getting user defined pb bkgs

kh99
03-03-2015, 02:41 PM
Oh, OK, then just move it to postbit_display_complete and you're good.

Dr.CustUmz
03-03-2015, 02:45 PM
=) thank you thank you