Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2008-05-22 00:07:23

wet
Developer Emeritus
From: Schoerfling, Austria
Registered: 2005-06-06
Posts: 3,330
Website Mastodon

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

#2 2008-05-22 01:50:23

jdykast
Member
From: Tennessee
Registered: 2004-12-30
Posts: 119
Website

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

#4 2008-05-22 06:05:05

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

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

#5 2008-05-22 07:09:47

the_ghost
Plugin Author
From: Minsk, The Republic of Belarus
Registered: 2007-07-26
Posts: 907
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

#6 2008-05-22 07:25:51

wet
Developer Emeritus
From: Schoerfling, Austria
Registered: 2005-06-06
Posts: 3,330
Website Mastodon

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

#7 2008-05-22 09:11:23

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
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

#8 2008-05-22 14:29:55

hakjoon
Member
From: Arlington, VA
Registered: 2004-07-29
Posts: 1,634
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

#9 2008-05-22 17:08:36

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
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

#10 2008-05-22 17:39:31

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,090
Website GitHub Mastodon Twitter

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

#12 2008-05-23 01:16:38

hakjoon
Member
From: Arlington, VA
Registered: 2004-07-29
Posts: 1,634
Website

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

core :)


Shoving is the answer – pusher robot

Offline

Board footer

Powered by FluxBB