Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#13 2020-01-08 15:48:23

etc
Developer
Registered: 2010-11-11
Posts: 4,620
Website GitHub

Re: Alphabetical list of articles in a section

jakob wrote #320941:

Thanks for the pointer. So:

  • substr($string, 0, 1) is the php function and would need registering in the advanced options in the Admin › Preferences. TRUE
  • substring(string, 1, 1) is an XPath function and, I guess, does not need registering. TRUE
  • And the UPPER in sort="UPPER(Title)" is MySQL. Used only for sort, not needed if all articles titles start uppercased (or all lowercased).

You showed another example of that not all that long ago. It does requires quite a few forms, though you did mention in the past that simpler breakby expressions can go straight into the attribute.

Yes, you could go with

breakby="<txp:evaluate query='substring(<txp:title escape=''quote'' />, 1, 1)' escape='upper' />"

to spare a db form query. You should also be able (untested) to replace <txp:yield item="breakby" /> in alphaform with

<txp:evaluate query='substring(<txp:title escape="quote" />, 1, 1)' escape="upper" />

and use alphaform as both breakby and breakform attributes. It’s a readability/modularity question.

Offline

#14 2020-01-08 16:29:56

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 3,873
GitHub

Re: Alphabetical list of articles in a section

Honestly, these threads are better than TED talks. I learn so much.

Offline

#15 2020-01-08 21:06:32

etc
Developer
Registered: 2010-11-11
Posts: 4,620
Website GitHub

Re: Alphabetical list of articles in a section

Bloke wrote #320937:

I’ll mention that in the attribute docs. The slash-thing, not my lack of regex skills :)

For the record:

<txp:title trim="/(?<!^).*/" escape="upper" />

Offline

#16 2020-01-08 21:29:22

etc
Developer
Registered: 2010-11-11
Posts: 4,620
Website GitHub

Re: Alphabetical list of articles in a section

BTW, we could add first to available escape values. Or even consider integer values as substring length:

<txp:variable name="hello" value="welcome" />
<txp:variable name="hello" escape="3" /> <!-- outputs 'wel' -->
<txp:variable name="hello" escape="-2" /> <!-- outputs 'me' or 'lcome' or 'welco'? -->

Offline

#17 2020-01-08 22:19:41

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 10,720
Website GitHub

Re: Alphabetical list of articles in a section

Oooh interesting. If we’re going that way and it’s not going to clash with anything else…

<txp:variable name="hello" value="welcome" />
<txp:variable name="hello" escape="3" /> <!-- outputs 'wel' -->
<txp:variable name="hello" escape="3,4" /> <!-- outputs 'lcom'? -->
<txp:variable name="hello" escape="-2" /> <!-- outputs 'me'? -->
<txp:variable name="hello" escape="5,-2" /> <!-- outputs 'co'? -->
<txp:variable name="hello" escape="-5,4" /> <!-- outputs 'lcom'? -->

The only thing with using the from,count syntax is that it differs from PHP’s substr() insofar as it starts from 1 and not 0, for consistency with the single count syntax. That might confuse programmers at first, but everyone else should get it.

EDIT: not really sure if ‘escape’ is the right terminology though. If we’re doing this, shouldn’t we introduce a new global attribute? I’d suggest expanding trim (since we’re trimming the text by a number of characters) except it’s currently used to trim alphanumerics, and an integer is a valid character you might want to strip off.

Last edited by Bloke (2020-01-08 22:23:02)


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

Offline

#18 2020-01-09 08:41:56

phiw13
Plugin Author
From: Japan
Registered: 2004-02-27
Posts: 2,656
Website

Re: Alphabetical list of articles in a section

Oleg, that is some superb tag-fu you are displaying. Splendid.

I’m trying hard to understand – taking notes along with the URL of the thread to test and analyse once I am past the first strong cold of the year (ginger tea with the last of the yuzu).


Where is that emoji for a solar powered submarine when you need it ?

Offline

#19 2020-01-09 09:40:41

etc
Developer
Registered: 2010-11-11
Posts: 4,620
Website GitHub

Re: Alphabetical list of articles in a section

phiw13 wrote #320957:

(ginger tea with the last of the yuzu).

Yum…

Bloke wrote #320953:

not really sure if ‘escape’ is the right terminology though. If we’re doing this, shouldn’t we introduce a new global attribute? I’d suggest expanding trim (since we’re trimming the text by a number of characters) except it’s currently used to trim alphanumerics, and an integer is a valid character you might want to strip off.

Yep, escape will not do since comma is used as separator there. We could adopt 1%%9 syntax used in custom fields filter, and trim suits better indeed. But I’m not sure we need it in such a generality: extracting/removing 3 first letters can be useful on plugins/themes sites, but other cases look exotic.

Offline

#20 2020-01-09 10:04:26

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 10,720
Website GitHub

Re: Alphabetical list of articles in a section

etc wrote #320960:

Yep, escape will not do since comma is used as separator there.

Ah of course. If you think escape with an integer just for removing everything but the given N letters is worthwhile, by all means stick it in.


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

Offline

Board footer

Powered by FluxBB