Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#11 2020-01-08 14:15:06

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 3,939
Website

Re: Alphabetical list of articles in a section

etc wrote #320932:

Functions available in XPath 1.0. And for trim solution you’d need some look-behind pattern, but it looks overkill here.

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.
  • substring(string, 1, 1) is an XPath function and, I guess, does not need registering.
  • And the UPPER in sort="UPPER(Title)" is MySQL.

I’m writing this down as much to help me (and others) remember 😳!

etc wrote #320935:

a good breakby exercise…

This, too, I will need to familiarise myself with as it looks very powerful and gets around an age-old problem with markup structures and if_different. 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.


TXP Builders – finely-crafted code, design and txp

Offline

#12 2020-01-08 14:16:11

philwareham
Core designer
From: Haslemere, Surrey, UK
Registered: 2009-06-11
Posts: 3,396
Website

Re: Alphabetical list of articles in a section

Thanks Oleg, works perfectly! That’s some pro level tag-fu there. 😀

I didn’t even know you could use a form as a breakby. And I don’t pretend to know how it all works, but it does.

Offline

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

etc
Developer
Registered: 2010-11-11
Posts: 3,940
Website

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
Admin
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 3,171

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: 3,940
Website

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: 3,940
Website

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: 9,786
Website

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,145
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: 3,940
Website

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: 9,786
Website

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