PDA

View Full Version : Changing templates with plugins

Mrajp
14 Dec 2009, 20:37
Just when I thought I had finally understood a small percentage of the vBulletin code, a completely new (but very powerful) template syntax has been released! :D

I have a small piece of code that adds an extra checkbox when a user is posting a reply. This ultimately adds some text to the message area and changes the prefix. Unfortunately with the new version, the page wont even load.

I've read some of the template articles and examined some 4.0 mods. However, they are at a level higher than my current vBulletin code comprehension.

Here is the code that is compatible with vB 3.8 using the "newreply_form_complete" hook:

$str = "<!-- Some comment in a template-->";$replace = "<br />
<input type='checkbox' name='resolved' value='1' />Resolution?
";

$vbulletin->templatecache['newreply'] = str_replace($str,$str.$replace,$vbulletin->templatecache['newreply']); There is also another plugin hooked to "newreply_post_start" that massages the data. It probably isn't compatible either, but I'll cross that bridge when I get to it. Is there still a way to perform the functionality of my current code? If so, could someone give me some guidance? Lynne 14 Dec 2009, 20:42 Is there a question here? Mrajp 15 Dec 2009, 15:32 Whoops! I just realized I forgot to ask one. Thanks Lynne! Is there still a way to perform the functionality of my current code? If so, could someone give me some guidance? Thanks in advance. BBR-APBT 15 Dec 2009, 15:46 It would be like this.$str = "<!-- Some comment in a template-->";
$replace = "<br /><input type='checkbox' name='resolved' value='1' />Resolution?";$vbulletin->templatecache['newreply'] = str_replace($str,$str.$replace,$vbulletin->templatecache['newreply']);

Mrajp
15 Dec 2009, 21:22
It would be like this.

$str = "<!-- Some comment in a template-->";$replace = "<br /><input type='checkbox' name='resolved' value='1' />Resolution?";

$vbulletin->templatecache['newreply'] = str_replace($str,$str.$replace, $vbulletin->templatecache['newreply']); I don't mean to seem ignorant, but the only difference I see between your code and mine is that the$replace string is all on one line. Are you saying that vB 4.0 can only handle 1 line replacement strings?

The above code still doesn't work in vB 4.0

BBR-APBT
15 Dec 2009, 22:09
I don't mean to seem ignorant, but the only difference I see between your code and mine is that the $replace string is all on one line. Are you saying that vB 4.0 can only handle 1 line replacement strings? The above code still doesn't work in vB 4.0 With the proper hook location? process_templates_complete Mrajp 17 Dec 2009, 09:55 With the proper hook location? process_templates_complete Well, I originally didn't have the hook location set to "process_templates_complete". However, even after changing the hook location, I get the following error message and the page does not load: Parse error: syntax error, unexpected T_STRING in D:\wamp\othersites\beta\includes\class_core.php(3917) : eval()'d code on line 104 I've hardcoded the replace string into the style just to verify that the HTML is correct. When hardcoded, the page loads without error and the checkbox appears. Any Ideas? BBR-APBT 17 Dec 2009, 16:03 Can I see your exact code. You can post the error all day long with out the code its no good. Mrajp 17 Dec 2009, 20:16 Most certainly, Here is the section of the style 'newreply' with the comment </div> <vb:if condition="$show['additional_options']">
<div class="blockbody formcontrols">

<vb:if condition="$show['misc_options']"> <div class="blockrow"> <!-- Some Comment --> <ul class="checkradio group"> <vb:if condition="$bbuserinfo['signature'] != ''">
<li>
<label for="cb_signature"><input type="checkbox" name="signature" value="1" id="cb_signature" tabindex="4" {vb:raw checked.signature} /> {vb:rawphrase show_your_signature}</label>

Here is my complete plugin code on the 'process_templates_complete' hook:

$str = "<!-- Some Comment -->";$replace = "<br /><input type='checkbox' name='resolved' value='1' />Resolution?";

$vbulletin->templatecache['newreply'] = str_replace($str,$str.$replace,$vbulletin->templatecache['newreply']); I'm running vB 4.0 RC2. Please let me know if you need any more information. Thanks Again. BBR-APBT 17 Dec 2009, 20:44 Try this$str = "<!-- Some Comment -->";

$replace = '<br /><input type="checkbox" name="resolved" value="1" />Resolution?';$vbulletin->templatecache['newreply'] = str_replace($str,$str.$replace,$vbulletin->templatecache['newreply']);

I switched the " and ' around.

ragtek
17 Dec 2009, 20:58
My question is a little bit offtopic.

Can the new vB4 Template Mering be used for this?
http://www.vbulletin.com/forum/entry.php?2350-vB-4-0-Template-Merging-and-3-Way-Comparison

Anybody tried this?

BBR-APBT
17 Dec 2009, 21:29
My question is a little bit offtopic.

Can the new vB4 Template Mering be used for this?
http://www.vbulletin.com/forum/entry.php?2350-vB-4-0-Template-Merging-and-3-Way-Comparison

Anybody tried this?

It should stay there with upgrade but I don't trust it my self as I haven't tested that feature out enough yet.

Mrajp
18 Dec 2009, 10:28
Try this

$str = "<!-- Some Comment -->";$replace = '<br /><input type="checkbox" name="resolved" value="1" />Resolution?';

$vbulletin->templatecache['newreply'] = str_replace($str,$str.$replace,\$vbulletin->templatecache['newreply']);

I switched the " and ' around.

Switching the string identifiers fixed the problem. Thank you so very much! :)

My question is a little bit offtopic.

Can the new vB4 Template Mering be used for this?
http://www.vbulletin.com/forum/entry.php?2350-vB-4-0-Template-Merging-and-3-Way-Comparison

Anybody tried this?

This looks interesting, I'm going to have a lot of style changes to make and I may try this.

ragtek
18 Dec 2009, 10:33
If it's not working, try tms!