2008-05-22 00:07:23

wet
Developer
omega
Real name: Robert
From: Lenzing, Austria
Known languages: de-AT, en, PL/M-80
Website

Central storage for site-wide constants: Helpful?

Imagine…

Imagine a future tag which would allow a site/theme designer to register constants at a central location (a form or the location near the top of a page template) and use them later on elsewhere, for instance as the e-mail address for zem_contact_reborn’s to attribute or as the AdSense Publisher id for all three AdSense forms which are scattered throughout your template.

How would you benefit from this?

In detail (using the yet unofficial Textpattern 4.0.7’s tag attribute parsing):

Somewhere in the very beginning of a template you would define names & values, just like you do on your desktop calculator’s “memory” keys:

<txp:register name="site-owner" value="john.doe@example.com" />
<txp:register name="adsense-pub" value="pub-9999999" />
<txp:register name="client-is-always-right" value="yesss" />

Later:

<txp:zem_contact to='<txp:register name="site-owner"  />' />

Conditionals would come handy at times

<txp:if_register name="client-is-always-right">
<!-- will change in two weeks, I'm sure -->
<txp:css n="fugly" />
</txp:if_register>

Elsewhere:

<script type="text/javascript"><!--
google_ad_client = '<txp:register name="adsense-pub" />';
google_ad_width = 120;
google_ad_height = 240;
//-->
</script>

Basically, you could control arbitrary aspects of your site’s implementation at one central place.

Thoughts? Pro? Con?

Offline

 

2008-05-22 01:50:23

jdykast
Member
zêta
Real name: Jason
From: Tennessee
Website

Re: Central storage for site-wide constants: Helpful?

I like the idea; very clever.

Offline

 

2008-05-22 01:59:28

Mary
Sock Enthusiast
omega
From: Canada

Re: Central storage for site-wide constants: Helpful?

“register” doesn’t immediately convey what it does, particular when we already have such functions as register_tab, etc. Something like var would be better.

I’d much rather be defining these things in the admin itself somewhere, rather than in some page template where I’d forget where it was. Then having the tag allow you to override the value on an individual basis when it is needed (not often).

i.e., default client-is-always-right is yes but say on one page I want it to be no I could use <txp:var name="client-is-always-right" value="no" />.


My email address has changed recently. If you need to contact me, use the forum contact form.

Offline

 

2008-05-22 06:05:05

maniqui
Moderator
omega
Real name: Julián
From: Buenos Aires, Argentina
Known languages: es,en

Re: Central storage for site-wide constants: Helpful?

So this will be something like “page template variables” or “custom fields for page templates”, right?

It would be a nice addition, particularly if those tags, being at the beginning of the template, can also be wrapped by conditionals, like txp:if_section (or any other), which probably is something you already though about.


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

 

2008-05-22 07:09:47

the_ghost
Plugin Author
pi
Real name: Victor
From: Minsk, The Republic of Belarus
Known languages: Belorussian, English, Russian, German, Italian, France, Turkish
Website

Re: Central storage for site-wide constants: Helpful?

If there will conditionals, it would be nice to have some check:

<txp:if_register name="client" isempty="1"> or <txp:if_register name="client" isempty="0"> or
<txp:if_register name="client" isset="0"> or <txp:if_register name="client" isset="1">

And, honestly saying, i’d like to see tag <txp:var /> insted of <txp:register />


Providing help in hacking ATM! Come to courses and don’t forget to bring us notebook and hammer! What for notebook? What a kind of hacker you are without notebok?

Offline

 

2008-05-22 07:25:51

wet
Developer
omega
Real name: Robert
From: Lenzing, Austria
Known languages: de-AT, en, PL/M-80
Website

Re: Central storage for site-wide constants: Helpful?

Mary wrote:

I’d much rather be defining these things in the admin itself somewhere, rather than in some page template where I’d forget where it was.

One of the basics of my idea was to leave no traces in the database. Think templates, shortcuts to development ideas, variant testing. Maybe I’m wrong, but putting these into a central form (e.g. named settings) would suffice.

the_ghost wrote:

If there will conditionals, it would be nice to have some check…

Conditionals would test for value(s) and, in case no value is specified, for existence of a var. I.e.

<txp:if_register name="client" value="foobar"> 

or

<txp:if_register name="client">

Offline

 

2008-05-22 09:11:23

ruud
Developer emeritus
omega
Real name: Ruud van Melick
From: a galaxy far far away
Known languages: li,nl,en,(de)
Website

Re: Central storage for site-wide constants: Helpful?

Mary wrote:

“register” doesn’t immediately convey what it does, particular when we already have such functions as register_tab, etc. Something like var would be better.

“var” is a reserved keyword in PHP and can’t be used for function names. But since it can’t be a function name, the parser could check for txp_var instead (whenever an unknown tag is found), which is faster than the workaround for tpt_link.

Offline

 

2008-05-22 14:29:55

hakjoon
Moderator
psi
Real name: Patrick
From: Arlington, VA
Known languages: en, pt
Website

Re: Central storage for site-wide constants: Helpful?

How about <txp:variable name="foo" value="bar" /> it’s what XSLT does. I love the idea BTW.


Shoving is the answer – pusher robot

Offline

 

2008-05-22 17:08:36

ruud
Developer emeritus
omega
Real name: Ruud van Melick
From: a galaxy far far away
Known languages: li,nl,en,(de)
Website

Re: Central storage for site-wide constants: Helpful?

^^ +1 on tag naming.

Who thinks this should be a plugin and who thinks this should go into TXP core?

Offline

 

2008-05-22 17:39:31

colak
Admin
omega
Real name: Yiannis
From: Cyprus
Known languages: el, en
Website

Re: Central storage for site-wide constants: Helpful?

Vote for core:)

Offline

 

Powered by FluxBB