Version: 1.0.0, by Milad
Developer Last Online: Nov 2023
Category: Administrative and Maintenance Tools -
Version: 3.6.5
Rating:
Released: 04-23-2007
Last Update: Never
Installs: 11
Uses Plugins
No support by the author.
Description:
This will enable modifications writers to edit templates on fly, to make there modifications as easy-to-install as possible. It consists of some functions, which had been written to ease template edits, without any actual editing from the webmasters side,
Installation:
Just import the XML file as a product.
Click install to receive updates and support.
Documentation:
All functions are declared in the hook init_startup, with Execution Order of 1, to be the first plug-in which is being executed in the whole scripts.
string $templatename: The template name to modify (ex: header, footer etc.).
string $location: A unique text in the template, where you want to insert your addition. If this text is not unique then the addition will be joined to all instances.
string $addition: The addition.
mixed $position: has two possible values, after (The default one): to insert the addition after the location, before: to insert the addition before the location.
string $templatename: The template name to replace in (ex: header, footer etc.).
string $texttofind: A unique text in the template to replace. If this text is not unique then all instances will be replaced.
string $texttoreplace: The replacing text.
print_template
Print a template in the browser, this helps you to see the working content of a template which is different from what do you see in the templates editor, so you can choose the proper text from a template.
return: nothing, but it prints the template in the browser
void print_template (string$templatename)
string $templatename: The template name to print in the browser (ex: header, footer etc.).
Restrictions:
You can't modify a template after it had been fetched by fetch_template function.
Because no template is cached before the hook global_start, using those functions in following hooks makes nonsense:
init_startup
style_fetch
cache_templates
Examples:
Add an image to the header:
PHP Code:
replace_in_template('header', ' ', '<img src="bla bla bla" alt="" border="0" />');
Insert a template inside another template, this will reduce the number of eval()s leading to better performance.
Notes for coders:
Feel free to use those functions in your mods, and please don't forget to add a dependency for this product (edit_templates_onfly). This will guarantee that every user of your mod will install this modification, so your mod will function properly, this mod will be a centralized method to edit templates, a method which is subject to be developed well, so you can't copy those functions in your mods.
Your suggestions and participations are welcomed.
Change log:
April, 19 2007, Initial release 1.0.0, functions: insert_to_template, delete_from_template, replace_in_template and print_template.
Credits:
The first person whom I saw uses this method to edit templates is Zero Tolerance in his vBShout mod, I learned it there.
Show Your Support
This modification may not be copied, reproduced or published elsewhere without author's permission.
Here's an example from one of my modifications using preg_replace in order to make on-the-fly template changes to all templates -- including modified ones:
The problem with using str_replace is that most people have a tendency to edit their templates. Thus, the static text you're searching the template for may have been changed. Now, if the text has been removed altogether there's nothing you can do -- however, if say by default you're looking for: