Gossamer Forum
Quote Reply
Using less globals
I habe lots of globals used in my version 2.12 and I have lots of modifications.

Now I want to reduce my globals, and here is my question?

How can I use funtions or values like globals, but only in specified scirpts or pages ?

I do not know anything about plugins, but I hope taht there is a way to have some funktions grouped for special needs in special scripts, for example:

- all search related globals are only used in search, search_error and search_results
- all user related globals are only used in user.cgi, login, add and modify
- lastlink is only used in build

Would be glad for any hint...

Thanks, Christian
Quote Reply
Re: [cwschroeder] Using less globals In reply to
Sorry, but I'm not quite sure what you're trying to do. Having a lot of globals isn't generally a big problem as long as they aren't run unnecessarily.

Adrian
Quote Reply
Re: [cwschroeder] Using less globals In reply to
This is a good idea to group the globals.
What Brewt is saying has nothing to do with the reality of some of us have to face: dozens of globals that you have somehow to keep track and document on what is what and what each does!
In my case I running more than 30 globals and all showing up in one single page. What a mess!

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Blondies can have brains (sometimes...)
Quote Reply
Re: [cwschroeder] Using less globals In reply to
You can just create a Plugin with no hooks. Then you can move globals into it - but wherever you call them in your templates you will have to replace global_name with Plugins::Plugin_Name::global_name.
Quote Reply
Re: [afinlr] Using less globals In reply to
Hi,

Exactly :) If people don't know how to make a plugin, I've created one that can be used for this job (attached).

All you need to do, is:

1) Add in your globals to the /admin/Plugins/MyGlobals.pm file.

Remember, globals start with sub { } , but in the .pm file, they need a name. The easiest way to name the "routines", is by the same name as the global.

For example, if we have a global called do_trim, then the routine would look like

Code:
sub do_trim {
# code here
}

2) Then, in your template - you need to rename the calls to your globals.

Again, the above example: do_trim - you would look for instances of <%do_trim%> , and change to: <%Plugins::MyGlobals::do_trim()%>

Hope that helps someone =) (its easy enough for the people who know what they are doing, but I know it can be a daunting thought for the more novice of you out there :))

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!