Gossamer Forum
Home : Products : DBMan SQL : Discussion :

access same template global within more than one template set

Quote Reply
access same template global within more than one template set
Is it possible to create template global that is accessible from ALL template sets (instead of just one)? Or would I need to create a new/add to an existing .pm file? This would be a very valuable tool, as there is currently a great deal of redundancy in my template globals (10 different template sets each needing the same global to generate today's date, for example). Thanks.

Fractured Atlas :: Liberate the Artist
Services: Healthcare, Fiscal Sponsorship, Marketing, Education, The Emerging Artists Fund
Quote Reply
Re: [hennagaijin] access same template global within more than one template set In reply to
Please excuse the premature post - I just figured this out. For any future readers, I'm pretty sure the best solution is indeed to create a new perl module and put it in admin/Dbsql. Presumably these new files will be "upgrade safe" and not be deleted or overwritten if/when the version of DBManSQL is upgraded?

Fractured Atlas :: Liberate the Artist
Services: Healthcare, Fiscal Sponsorship, Marketing, Education, The Emerging Artists Fund
Quote Reply
Re: [hennagaijin] access same template global within more than one template set In reply to
I've been looking for something like this as I also have multiple template sets that need the same global. I'm still new to DBMan SQL and would appreciate it if you could post an example of the new perl module that you put in the admin/Dbsql directory. Does everything in the admin/Dbsql directory automatically get loaded?

Thanks

Simon.
Quote Reply
Re: [jai] access same template global within more than one template set In reply to
As hennagaijin mentioned, you can create a file sample.pm in admin/Dbsql which contains:

package Dbsql::sample;

use strict;

sub dump() {
#----------------------------------------------
#
my $tags = GT::Template->tags;
use Data::Dumper;
return "<pre>".Dumper($tags->{home})."<pre>";
}

1;

And then, you can use <%Dbsql::sample::dump%> in your templates

TheStone.

B.
Quote Reply
Re: [jai] access same template global within more than one template set In reply to
I'm still figuring out how to get the most use out of DBManSQL myself, so I'm happy to share what little I'm learning. Smile

For my very first foray into creating a new perl module I created Custom.pm, which for now contains two very simple subroutines (just used for testing purposes, really):

get_today - returns today's date
get_today_plus90 - returns a date 90 days from today

After putting these both in the Custom.pm file, which is uploaded into the admin/Dbsql directory, they can be called from within any template by using something like:

Today is <%Dbsql::Custom::get_today%>
In 90 days it will be <%Dbsql::Custom::get_today_plus90%>

The format is pretty much just:
<%Dbsql::[NAME_OF_MODULE_W/O_EXTENTION]::[SUB_ROUTINE]%>

As far as I can tell, all perl modules are available from all templates, so this is a good way to accomplish the equivalent of cross-template globals.

Custom.pm, such as it is, is attached.

Fractured Atlas :: Liberate the Artist
Services: Healthcare, Fiscal Sponsorship, Marketing, Education, The Emerging Artists Fund
Quote Reply
Re: [TheStone] access same template global within more than one template set In reply to
As Henagaijin asked -

Presumably these new files will be "upgrade safe" and not be deleted or overwritten if/when the version of DBManSQL is upgraded?
Is that correct??

Thanks

Simon.
Quote Reply
Re: [jai] access same template global within more than one template set In reply to
Yep, it will not be deleted/overwritten when DBMan is upgaded.

TheStone.

B.