Edit Templates On Fly - A step towards easy-to-install modifications
Mod Version: 1.0.0, by Milad
This modification is in the archives.
| vB Version: 3.6.5 |
Rating: (3 votes - 4.67 average) |
Installs: 11 |
| Released: 24 Apr 2007 |
Last Update: Never |
Downloads: 47 |
Not Supported
Uses Plugins
|
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.
Current version contains the following functions: - insert_to_template
Inserts something to a template.
void insert_to_template (string $templatename, string $location, string $addition, [mixed $position = 'after'])
- 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.
- delete_from_template
Deletes something from a template.
void delete_from_template (string $templatename, string $texttodelete)
- string $templatename: The template name to delete from (ex: header, footer etc.).
- string $texttodelete: A unique text in the template to be deleted. If this text is not unique then all instances will be deleted.
- replace_in_template
Replaces a text in a template.
void replace_in_template (string $templatename, string $texttofind, string $texttoreplace)
- 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.
PHP Code:
insert_to_template('FORUMHOME', '<!-- logged-in users -->', $vbulletin->templatecache['sometemplate'], 'before');
Of course the template (sometemplate) must be already cashed.
- Replace the index.php in the header with ./
PHP Code:
replace_in_template('header', 'href=\"" . $GLOBALS[\'vbulletin\']->options[\'forumhome\'] . ".php" . $GLOBALS[\'vbulletin\']->session->vars[\'sessionurl_q\'] . "\"', 'href=\"./" . $GLOBALS[\'vbulletin\']->session->vars[\'sessionurl_q\'] . "\"');
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.
Download
This modification is archived, downloads are still allowed.
product-edit_templates_onfly.xml (2.3 KB, 57 downloads)
|