Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
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
Re: Central storage for site-wide constants: Helpful?
I like the idea; very clever.
Offline
#3 2008-05-22 01:59:28
- Mary
- Sock Enthusiast
- Registered: 2004-06-27
- Posts: 6,236
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" />
.
Offline
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.
Offline
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
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
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
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
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
Re: Central storage for site-wide constants: Helpful?
Vote for core:)
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
#11 2008-05-22 17:58:54
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: Central storage for site-wide constants: Helpful?
colak wrote:
Vote for core:)
+1 :)
Offline
Re: Central storage for site-wide constants: Helpful?
core :)
Shoving is the answer – pusher robot
Offline