Categories > TinyButStrong general >

Any way to define a set of variables ONCE to be used among multiple site pages?

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Ian
Date: 2008-12-09
Time: 21:55

Any way to define a set of variables ONCE to be used among multiple site pages?

Hi,

I have a site that is multilingual and I am using Gettext and PO files to manage different languages.  One part of my site is a CSS-driven navigation menu that is included on every page (added as an include using the TBS "onload" function)  This menu has quite a bit of text that requires translation which I have replaced with tbs variable placeholders and have defined the variables for this text in the underlying .php file that is associated with the page's main .html template. 

While this works fine and the placeholders get replaced by the appropriate text in the multiple languages, I do not look forward to having to define the exact same text for these navigation links in the .php file for each distinct page in my site.  I would like to define the values for this navigation menu ONCE and then just re-use it for each new page.

Is there a way to create a variable definition file which can be re-used (like an include) in each distinct .php page?  I have tried to do this using PHP's native "include" functionality, but TBS throws a bunch of errors when I do that, as it tries to build the HTML output and cannot find the variable definitions in the .PHP file...

If there isn't a way to do this, it's not the end of the world, but it would surely be nice if there were...

Thanks,

Ian
By: TomH
Date: 2008-12-10
Time: 04:00

Re: Any way to define a set of variables ONCE to be used among multiple site pages?

Consider using PHP's auto_prepend feature.

I use the php auto_prepend feature to load a single file that does all of the following...
(a) load the TBS class
(b) load my db class and db connection parms
(c) load application specific vars/functions
(d) set caching parms for TBS and DB queries

Using Apache .htaccess file is my approach to implementing this so that none of the individual application files are burdened by any of the above.

Adding default parms/vars/arrays such as you identified becomes trivial when using the auto_prepend approach.

My 2cents,
TomH
By: Ian
Date: 2008-12-10
Time: 17:35

Re: Any way to define a set of variables ONCE to be used among multiple site pages?

Hi TomH,

Thanks for your feedback on this.  I hadn't considered using auto-prepend for this, but it would make sense.  I'll check it out later today.

Best,

Ian