PDA

View Full Version : Edit template with hook?


Kyojii
07-08-2012, 12:24 PM
I have a file I would like to include on the editprofile page. Rather than edit all of the templates and include it in every one I thought it would be easier to make a hook that appends it to all of them. However when I tried this for some reason the $headinclude variable gets replaces with only "0".


if ($_REQUEST['do'] == 'editprofile'){
$headinclude += '<script type="text/javascript" src="/includes/bubbles.js"></script>';
}

echo htmlspecialchars($headinclude);
echo '<br><br><br>';
$headinclude += '<script type="text/javascript" src="/includes/bubbles.js"></script>';
echo htmlspecialchars($headinclude);

Output of above code:
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> <base href="" /><!--[if IE]></base><![endif]--> <meta name="generator" content="vBulletin 4.1.7" /> <link rel="Shortcut Icon" href="favicon.ico" type="image/x-icon" /> <meta name="keywords" content="" /> <meta name="description" content="" /> <meta property="fb:app_id" content="343071649037238" /> <meta property="og:site_name" content="" /> <meta property="og:description" content="" /> <meta property="og:url" content="" /> <meta property="og:type" content="website" /> <script type="text/javascript" src="clientscript/yui/yuiloader-dom-event/yuiloader-dom-event.js?v=417"></script> <script type="text/javascript" src="clientscript/yui/connection/connection-min.js?v=417"></script> <script type="text/javascript"> <!-- var SESSIONURL = ""; var SECURITYTOKEN = "1341753294-5bf2ad92bde7df16216e232b4783009f4c143736"; var IMGDIR_MISC = "images/misc"; var IMGDIR_BUTTON = "images/buttons"; var vb_disable_ajax = parseInt("0", 10); var SIMPLEVERSION = "417"; var BBURL = ""; var LOGGEDIN = 504 > 0 ? true : false; var THIS_SCRIPT = "profile"; var RELPATH = "profile.php?do=editprofile"; var PATHS = {forum : ""} // --> </script> <script type="text/javascript" src=""></script> <link rel="alternate" type="application/rss+xml" title="" href="" /> <link rel="stylesheet" type="text/css" href="css.php?styleid=13&amp;langid=1&amp;d=1339672467&amp;td=ltr&amp;sh eet=bbcode.css,editor.css,popupmenu.css,reset-fonts.css,vbulletin.css,vbulletin-chrome.css,vbulletin-formcontrols.css," /> <!--[if lt IE 8]> <link rel="stylesheet" type="text/css" href="css.php?styleid=13&amp;langid=1&amp;d=1339672467&amp;td=ltr&amp;sh eet=popupmenu-ie.css,vbulletin-ie.css,vbulletin-chrome-ie.css,vbulletin-formcontrols-ie.css,editor-ie.css" /> <![endif]-->


0

kh99
07-08-2012, 12:30 PM
Try using .= in place of += .

Kyojii
07-08-2012, 01:15 PM
Thanks, that worked.

--------------- Added 1341760064 at 1341760064 ---------------

I have another question, is there a list of what the template variables actually are? I noticed there's template hooks so I tried to use regex to add something after one of the hooks in postbit_legacy however in php it seems the variable $postbit_legacy doesn't exist.

cellarius
07-09-2012, 04:54 AM
postbit_legacy is a template, why would it exist as a variable? And you don't need regex to add something to a template hook, you just use a plugin at parse_templates hook, doing
$template_hook['template_hook_name'] .= "whatever";

Kyojii
07-09-2012, 06:41 AM
postbit_legacy is a template, why would it exist as a variable? And you don't need regex to add something to a template hook, you just use a plugin at parse_templates hook, doing
$template_hook['template_hook_name'] .= "whatever";

Yeah, I found this out. I thought it would exist as a variable because $headinclude $header etc do.

SkyStryder
07-26-2012, 06:21 PM
I was actually trying something like this. There seems to be a problem
if you need to add a vb variable like {vb:raw somedata} in the middle
of "whatever". I tried "string" . {vb:raw somedata} . "string" but that
didn't help. 8-( Hints are greatly appreciated.



$template_hook['template_hook_name'] .= "whatever";

cellarius
07-26-2012, 06:25 PM
You can't use template variables in plugins. Plugins are PHP only. You need to use the PHP equivalent of the template variable.