View Full Version : newthread -- template hooking before message area
Masked Crusader
12-26-2010, 06:06 AM
Hey all.
I have finally finished my product and am trying to make sure that I am following all of the vBulletin standards prior to release. I have a template that I want to insert prior to the "messagearea" in the "newthread" template.
Here is the code I have thus far:
$newTemplate = vB_Template::create('qma'); //my custom template
$rendered = $newTemplate->render();
$find = "{vb:raw messagearea}";
$vbulletin->templatecache['newthread'] = str_replace($find, $rendered . "\n" . $find, $vbulletin->templatecache['newthread']);
Now, the templatecache has the correct values and is populated. The issue is what to use for the "find". When I did a "print_r" on the templatecache for the newthread template, it shows the output for the message area part like this:
' . $message . '
So, I tried searching for that as well, and no luck. Of course, there is no pre-defined vBulletin hook in this position, so this is the only way to do it that I know of without doing actual template edits with the newthread template, which I definitely want to stay away from.
Any help on what to use for the "$find" condition would be greatly appreciated!
Lynne
12-26-2010, 04:22 PM
What hook location are you using? And you tried just using $find = $message; ?
Masked Crusader
12-26-2010, 06:12 PM
I am trying to put my template ('qma') right before the message area. I want it to look like this:
http://img408.imageshack.us/i/armoryposition.png/
Right now, I actually have the HTML block of code in the 'newthread' template as I cannot figure out how to get it into that position without doing it that way. I tried searching for the message are with the following code:
global $vbulletin;
$is_qma_enabled = false;
if($vbulletin->options['qma_onoff'] == 1){
$forums_enabled = explode(',', $vbulletin->options['qma_forumid']);
$is_qma_enabled = in_array($vbulletin->GPC['forumid'], $forums_enabled);
}
if($is_qma_enabled == true){
$show['qma_enabled'] = true;
$newTemplate = vB_Template::create('qma');
$rendered = str_replace( "<", "<", $newTemplate->render() );
$find = "messagearea";
$vbulletin->templatecache['newthread'] = str_replace("messagearea", "", $vbulletin->templatecache['newthread']);
$vbulletin->templatecache['newthread'] = str_replace("' . $ . '", $rendered, $vbulletin->templatecache['newthread']);
}
It works in finding the area that the template should be put (the 'qma' template also has the 'messagearea' part that I am erasing with the above str_replace), but after trying to I get an PHP runtime error:
Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/maskedcrusader/includes/class_core.php(4414) : eval()'d code on line 141
It is having a problem with the 'eval' for the template and I cannot seem to find any PHP errors in my code that would cause that error.
BirdOPrey5
12-26-2010, 07:19 PM
Have you tried commenting out some lines so you can narrow down exactly which one is causing the error? My guess is the last line but best to know for sure before speculating.
Lynne
12-26-2010, 09:28 PM
I always start with something that works and then build from there. This works:
global $vbulletin;
$find = ' . $messagearea . ';
$add = '."New Text".';
$vbulletin->templatecache['newthread'] = str_replace(
$find,
$add,
$vbulletin->templatecache['newthread']
);
Masked Crusader
12-27-2010, 12:38 AM
Alright, I figured out where the problem is occuring, but the question is how the heck to correct it.
On this line of PHP code:
$newTemplate = vB_Template::create('qma');
$add = $newTemplate->render();
The render is causing the issue.
So, when it goes to 'eval' the template, it is causing the issue. Here is what my template code looks like:
<vb:if condition="$show['qma_enabled']">
<div class="blockrow">
<label class="full">Quick Masked Armory:</label>
<div style="padding-top: 5px;">
<select id="locale" name="char_1_locale" class="primary" style="width: 75px;">
<option value="US">US</option>
<option value="EU">EU</option>
</select>
<input type="text" id="server_1" value="Server Name" name="char_1_server" size="25" class="primary textbox" />
<input type="text" id="char_name_1" value="Character Name" name="char_1_name" size="25" class="primary textbox" />
<a style="cursor: pointer;" onClick="createArmory(document.vbform.char_1_server.value, document.vbform.char_1_name.value, document.vbform.char_1_locale.value, 1);">Create</a>
</div>
<div style="padding-top: 5px; padding-bottom: 10px; display: none; color: orange;" id="char_1_error"></div>
<br/>
<div style="font-size: 11px;">Boxes above are reusable to add as many characters as you want to your post!</div>
<div style="font-size: 11px;">More Masked Armory features available at <a href="http://www.maskedarmory.com" target="_blank">MaskedArmory.com</a>. -- Copyright © 2010</div>
</div>
<div class="blockrow"></div>
</vb:if>
The 'eval' issue hits on this line at the top of the template:
<div class="blockrow">
Is there something wrong with my HTML or the way vB is evaluating it?
BirdOPrey5
12-27-2010, 01:24 AM
If you remove the <vb:if> conditional from the template do you still get the error?
Masked Crusader
12-27-2010, 01:47 AM
I got it all fixed. Man, vB4 templating is a pain in the butt!
New question -- is there a guide on how to make template groups for installation with the product? I have a CSS file and two template files that I want to put into a template group that will install with the product hooks.
--------------- Added 1293423347 at 1293423347 ---------------
Figured it all out. Have a completed product that installs perfectly!
vBulletin® v3.8.12 by vBS, Copyright ©2000-2024, vBulletin Solutions Inc.