MyBB Community Forums

Full Version: Append Template Set
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Does anyone know a decent way or any way to append a template set as opposed to finding and replacing ? Sometimes I need to append or prepend template sets, but I've never found anything suitable.
I use this and it works;

On activation:
require MYBB_ROOT."/inc/adminfunctions_templates.php";
find_replace_templatesets("TEMPLATE_NAME", "#".preg_quote('FIND')."#i", 'FINDREPLACE');

On de-activation:
require MYBB_ROOT."/inc/adminfunctions_templates.php";
find_replace_templatesets("TEMPLATE_NAME", "#".preg_quote('FINDREPLACE')."#i", '', 0);
Finding and replacing is not the issue here. I use find and replace also. I use that all the time. I need a way to append or prepend a template set. For example if the end of a template has a div tag "</div>" and I want to place a variable below that tag, find and replace wont work in most cases, because the template more than likely has several div tags.

This is why I need to append or prepend a template regardless of whats in the templete.
You may use the same find replace code (I mentioned earlier). Then for finding the code in template you may select the text and copy that from the template and paste in "FIND" area. I'll suggest to copy two lines from the template. For example, if you've something like this:
<div>
{$yaldi}
<div>
Then FIND code would be something like this;
find_replace_templatesets("TEMPLATE_NAME", "#".preg_quote('<div>
{$yaldi}')."#i", 'FINDREPLACE');

Notice the line break.
No No No No No No No No. lol

I used find and replace, I understand find and replace, I know you can select several different lines in the template and replace them. But its not what im looking form. Im not looking for "alternatives", Im looking for a way to "append or prepend" a template no matter what it is the template. I know your only trying to help, but as Ive said I'm not looking for an alternative method.
Nobody has any solution for this ?
There is no real way of doing what you want for every template available in MyBB as it would require pre and post hooks for when a template is retrieved, and that doesn't exist. It would require modification of MyBB source to add that functionality.

If you have specific templates in mind, you would have to add variables at the beginning and the end of the templates. Then you would tie to the appropriate hooks that run before those templates are loaded, make the variables global in your function, and fill them with the template/data that you want inserted.
So are you doing this in a plugin or...?
Yes, Im wanting to append a variable on the end of a template via a plugin.
You could grab the template data form the database, then just append your data and manually re-add it to the database.
Pages: 1 2