We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Announcing GeeVar: A Global Variables Plugin

Development and Programming

Mr. Wilson's avatar
Mr. Wilson
131 posts
17 years ago
Mr. Wilson's avatar Mr. Wilson

I had a need for a plugin like this while working on a few client websites. I finally whipped this together today. Hopefully somebody else finds it useful.

Imagine this scenario: You have built an ExpressionEngine website for a client. Everything works great, but there’s a problem: the client needs to be able to change little pieces of relatively static text. You don’t want to let him into the templates because, well, he’ll screw them up. You don’t want to let him access global template variables for the same reason, and besides, those variables don’t have any formatting options. How can you allow the client to change data—such as the company’s address, or maybe even that “Welcome to our website” text on the homepage—quickly and easily?

GeeVar allows you to create global variables using the control panel’s publish and edit interface. In short, each variable is a weblog entry. That means you can have as many or as few as you need, and you can format each variable’s value however you like (e.g. “none”, XHTML, or even using something like Textile or a wysiwyg editor). The variables are retrieved without the extra processing weight of the Weblog Module. As a bonus, GeeVar’s variables are cached, so the plugin only accesses the database once per page load. Thus, you can use as many GeeVar tag pairs as you like, anywhere in your templates (or embedded templates) without fear of ramping up your query count. In addition, you can nest GeeVar variables, giving you the ability to store a company’s address in a variable like so

{geevar_company_name}
{geevar_company_street_address}
{geevar_company_citystatezip}
{geevar_telephone}
{geevar_fax}
{geevar_email}

and have it turn into

Wally's Widget World
1 Widget Way
Walla Walla, WA 11111
(555) 123-0987
(555) 123-0988
[email protected]

Sound like something you could use? Go try it out.

       
melissajc's avatar
melissajc
86 posts
17 years ago
melissajc's avatar melissajc

very interesting Mr. Wilson. We’ll be giving this one a try for sure. Thanks for sharing it.

       
Meirion's avatar
Meirion
127 posts
17 years ago
Meirion's avatar Meirion

Brilliant, that sounds like just what I was looking for. I’ll let you know how I get on with it.

Thank you

       
Meirion's avatar
Meirion
127 posts
17 years ago
Meirion's avatar Meirion

Mr Wilson, would the plugin still work if I add an extra field in the field group for a description of the variable? This would just be information for the client when they are updating their varibales, ie to explain where the variable appears, or what sections of the site it affects.

       
Mr. Wilson's avatar
Mr. Wilson
131 posts
17 years ago
Mr. Wilson's avatar Mr. Wilson

Yep, you can add anything extra you want. GeeVar just needs:

  • An appropriately-prefixed URL title (i.e. geevar_my_variable)
  • An appropriately-named value custom field (i.e. geevar_value)

It will also look at the custom field’s formatting.

GeeVar will ignore anything else. Field descriptions won’t hurt a thing. You could even add more custom fields if, for example, you wanted to access the data using exp:weblog:entries.

       
Jamie Pittock's avatar
Jamie Pittock
108 posts
17 years ago
Jamie Pittock's avatar Jamie Pittock

Hi, this does look really useful but we’re struggling to get it working. We’ve followed the instructions in the docs but we can’t get anything to output. It’s simply blank where the variable value should print.

If we turn PHP errors on we do get this error

Notice: Undefined variable: tagdata in /var/www/html/manage/plugins/pi.geevar.php on line 88

The server is running PHP5

       
Mr. Wilson's avatar
Mr. Wilson
131 posts
17 years ago
Mr. Wilson's avatar Mr. Wilson

I ran into that error myself yesterday. I think I must have posted the wrong version of the file. Could you give the current download (1.0.2) a try?

       
Jamie Pittock's avatar
Jamie Pittock
108 posts
17 years ago
Jamie Pittock's avatar Jamie Pittock

Excellent…yep that sorted it. Thanks!

       
yassiryahya's avatar
yassiryahya
33 posts
17 years ago
yassiryahya's avatar yassiryahya

Is there any way to implement Geevar with stand alone entry form so that I can make an edit form outside of the control panel? Any links with pointers? 😛

Thanks in advance.

P/S : Was trying out Geevar with the following code : <pre><code> {exp:geevar weblog="wrs_globalvars" var_prefix="var_"}

                            {var_logged_in_welcome_message}

                    {/exp:geevar}[/code]

With the following settings :

Weblog Full Name: WRS Global Variables Weblog Short Name: wrs_globalvars URL Title Prefix: var_

Field Order: 1 Field Label: Data Field Name: var_ Field Type: WYSIWYG

But still, the outputs shows “{var_logged_in_welcome_message}” in the browser. Any ideas?

       
Mr. Wilson's avatar
Mr. Wilson
131 posts
17 years ago
Mr. Wilson's avatar Mr. Wilson

I’ll start with your P.S. … Check the URL title of that entry. It should be “var_logged_in_welcome_message”. Is it? If not, there’s your problem.

As for getting Geevar to work with a stand-alone entry/edit form, it should work just like any other entry/edit form. Let me know if you run into any specific roadblocks.

       
jejuna's avatar
jejuna
105 posts
17 years ago
jejuna's avatar jejuna

Mr. Wilson:

I can’t get any output from the GeeVar plugin.

Here’s what I’ve got:

weblog: global 1 custom field: global_address 1 entry with url prefix: global_lvca_address Formatting: textile. I’m also using the TEH extension, if that makes a difference.

template:

{exp:geevar weblog="global"} {global_lvca_address} {/exp:geevar}

Output: {global_lvca_address}

Yes, the plugin is installed. What am I doing wrong?

Also tried it like this:

{exp:geevar weblog="global" var_prefix="global_" } {global_lvca_address} {/exp:geevar}

but still, no output.

       
Mr. Wilson's avatar
Mr. Wilson
131 posts
17 years ago
Mr. Wilson's avatar Mr. Wilson

GeeVar 1.0.4 has been posted. It now supports “meta” variables, such as status.

@jejuna: Can you download 1.0.4 and see if it fixes your problem? If not, do let me know. I haven’t tested with Textile and I’m not sure what the TEH extension is, so either of those could be the culprits.

       
jejuna's avatar
jejuna
105 posts
17 years ago
jejuna's avatar jejuna

I did download and install the new version, but still, no output.

It doesn’t seem to matter whether the text in the custom field is formatted as Textile, XHTML, or “none”, as I’m still getting no output.

I think I’ve done everything correctly:

  1. Created a weblog called “global”.
  2. Created a custom field called “global_address”.
  3. Put text in field. Url title string is “global_lvca_address”

In the template:

{exp:geevar weblog="global" var_prefix="global_"} {global_lvca_address} {/exp:geevar}

Output: {global_lvca_address}

Note: If I call it from the standard weblog:entries tag, like so:

{exp:weblog:entries weblog="global" entry_id="2"} {global_address} {/exp:weblog:entries}

It outputs fine, but defeats the purpose of the plugin!

Am I missing something? Any ideas are appreciated!

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.