Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Re: Poll: useful 'escape' transforms
philwareham wrote #308339:
just checking: these (global) attributes can be used on any tag, yes?
Almost: they are recognized by all tags, but their action can be different if the tag implements its own attribute processing. But most core tags are aligned, save for <txp:author />
etc where, say, escape="number"
is of little use.
I’d also be keen to have the global attributes at least mentioned on the attributes section of tag docs (not necessarily listed, but mentioned). It may even be good to have another page on tag basics explaining global attributes too (as I assume this list of globals will only get bigger in future releases). Same for
escape
– it probably merits another page on tag basics and mentions on tag doc pages.
From users POV it makes no difference whether an attribute is global or not, save for processing order. If escape
merits another page, it probably is only because of its abilities, but then some tags are also more powerful than others. Dunno how to structure the docs atm…
I would suggest that we keep attributes descriptions in some central place (tags cross-reference?) and pull it from there (via Ignore me, they act differently depending on tags.jQuery
or etc_query
or something, with a cache) on individual tags pages, to avoid text duplication.
Offline
#50 2017-12-19 17:48:14
- GugUser
- Member
- From: Quito (Ecuador)
- Registered: 2007-12-16
- Posts: 1,473
Re: Poll: useful 'escape' transforms
This is all very exciting, but the longer the discussion goes on, the less I understand.
I think many people, like me, will need detailed instructions for the large number of new features in version 4.7.
Thank you for your great work.
Offline
Re: Poll: useful 'escape' transforms
I’ve created a placeholder doc for explaining the escape
attribute, see here for the bare bones of it.
This needs to be filled out. I’ll try to get my head around it but it might be better if someone with better knowledge of that this new feature can write it instead of me.
I also think there are probably escape values that are missing from the list I currently have on there. Haven’t gone through the whole of this thread to find out.
Offline
Re: Poll: useful 'escape' transforms
GugUser wrote #308371:
This is all very exciting, but the longer the discussion goes on, the less I understand.
:-) The docs will be made clear, with plenty of examples.
But basically, this attribute – now applicable to all core tags (and plugins that don’t already do their own thing with the attribute) – will enable you to transform the content on-the-fly. Change its case, convert it to a number, pass it through Textile, remove spaces, remove all or specific tags, and so forth.
Very powerful stuff, that previously was the domain of plugins is now within the grasp of every tag. Exciting stuff indeed.
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Online
Re: Poll: useful 'escape' transforms
philwareham wrote #308372:
I’ve created a placeholder doc for explaining the
escape
attribute, see here for the bare bones of it.
I have added few examples, but am not the right person to judge whether they will suffice. As Stef says,
… basically, this attribute – now applicable to all core tags (and plugins that don’t already do their own thing with the attribute) – will enable you to transform the content on-the-fly.
I would add that there is no reason to limit ourselves to a fixed set of transforms. Just yield, and we can add a possibility to extend it (via a pref) with other functions (DB escaping and so on). This is also why
… there are probably escape values that are missing from the list …
Offline
#54 2017-12-21 11:27:34
- uli
- Moderator
- From: Cologne
- Registered: 2006-08-15
- Posts: 4,306
Re: Poll: useful 'escape' transforms
etc wrote #308381:
I would add that there is no reason to limit ourselves to a fixed set of transforms.
Oh, there’s one thing on my wish list: Some posts above there was an attribute to remove dots and commas and the dollar sign from prices. Could that be done in reverse, too? I mean inserting country specific separators for long strings of numerals after each third numeral (so 1000000 becomes 1,000,000) or simply swapping dots for commas (5,679.39 becomes 5.679,39, i.e. en/us to eu) and vice versa. Useful not only in yab_shop.
In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links
Offline
Re: Poll: useful 'escape' transforms
Hi Uli,
mind that escape
does not take extra parameters, only “transform” names. Hence, if you want to convert to a fixed format (say, corresponding to the current site language), this is doable (and already the case for the decimal separator). But if you are running a multilingual site, you’ll have to supply the needed format somehow.
Offline
Re: Poll: useful 'escape' transforms
I have modified escape="number"
so that it outputs the localized value, i.e. 1,234.78
for English language and 1 234,78
for French. There is also a new escape="float"
value that will output the computer-readable 1234.78
to use in calculations.
Offline
Re: Poll: useful 'escape' transforms
Doesn’t appear to work for me, but then I think my locale is ‘C’ so that’s kind of expected. It just strips out commas and leaves the decimal point.
Test suite:
<txp:variable name="cnum" value="12,345,4321" />
<txp:variable name="inum" value="123454321" />
<txp:variable name="dnum" value="12345.4321" />
<txp:variable name="enum" value="12.345,4321" />
<txp:variable name="bnum" value="12,345.4321" />
<dl>
<dt>Comma</dt>
<dd><txp:variable name="cnum" /></dd>
<dd><txp:variable name="cnum" escape="float" /></dd>
<dd><txp:variable name="cnum" escape="tidy, float" /></dd>
<dd><txp:variable name="cnum" escape="number" /></dd>
<dd><txp:variable name="cnum" escape="tidy, number" /></dd>
<dd><txp:variable name="cnum" escape="integer" /></dd>
<dt>Integer</dt>
<dd><txp:variable name="inum" /></dd>
<dd><txp:variable name="inum" escape="float" /></dd>
<dd><txp:variable name="inum" escape="tidy, float" /></dd>
<dd><txp:variable name="inum" escape="number" /></dd>
<dd><txp:variable name="inum" escape="tidy, number" /></dd>
<dd><txp:variable name="inum" escape="integer" /></dd>
<dt>Decimal (UK/US)</dt>
<dd><txp:variable name="dnum" /></dd>
<dd><txp:variable name="dnum" escape="float" /></dd>
<dd><txp:variable name="dnum" escape="tidy, float" /></dd>
<dd><txp:variable name="dnum" escape="number" /></dd>
<dd><txp:variable name="dnum" escape="tidy, number" /></dd>
<dd><txp:variable name="dnum" escape="integer" /></dd>
<dt>Decimal (Euro)</dt>
<dd><txp:variable name="enum" /></dd>
<dd><txp:variable name="enum" escape="float" /></dd>
<dd><txp:variable name="enum" escape="tidy, float" /></dd>
<dd><txp:variable name="enum" escape="number" /></dd>
<dd><txp:variable name="enum" escape="tidy, number" /></dd>
<dd><txp:variable name="enum" escape="integer" /></dd>
<dt>Mixed</dt>
<dd><txp:variable name="bnum" /></dd>
<dd><txp:variable name="bnum" escape="float" /></dd>
<dd><txp:variable name="bnum" escape="tidy, float" /></dd>
<dd><txp:variable name="bnum" escape="number" /></dd>
<dd><txp:variable name="bnum" escape="tidy, number" /></dd>
<dd><txp:variable name="bnum" escape="integer" /></dd>
</dl>
Result:
Comma
12,345,4321
12
123454321
12
123454321
12
Integer
123454321
123454321
123454321
123454321
123454321
123454321
Decimal (UK/US)
12345.4321
12345.4321
12345.4321
12345.4321
12345.4321
12345
Decimal (Euro)
12.345,4321
12.345
12.3454321
12.345
12.345432
12
Mixed
12,345.4321
12
12345.4321
12
12345.4321
12
Is that the expected outcome? Seems reasonable on my system but I dunno how it’ll fare on others who do have proper locales.
EDIT: Typo in test code.
Last edited by Bloke (2017-12-21 15:31:55)
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Online
Re: Poll: useful 'escape' transforms
If the locale thing works, how about a currency
option? NumberFormatter::CURRENCY
? Would that work? Or are we straying into obscure territory here?
<txp:newer escape="currency" />
Wot?!
Last edited by Bloke (2017-12-21 15:35:51)
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Online
Re: Poll: useful 'escape' transforms
It outputs localized number, not inputs them.
Currency would work, but it would output USD 666
, not $666
or 666$
. Why not, though.
Offline
Re: Poll: useful 'escape' transforms
Yeah, I was just pretending to have values in a range of possible input formats and see what it spat out.
For example, if an Italian editor wrote an article and inadvertently put into a custom field the value 1.234.567,89
(meaning: one million, two hundred and thirty four thousand, five-hundered and sixty-seven point eight nine) but the tag was set to output <txp:custom_field name="some_field" escape="number" />
it’s going to render it incorrectly if the front-end locale is English, right?
EDIT: I know there’s not a lot that can be done about this, I was just testing it because I was curious about your use of str_replace()
.
Last edited by Bloke (2017-12-21 16:00:11)
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Online