Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#331 2020-01-23 17:48:07

etc
Developer
Registered: 2010-11-11
Posts: 5,675
Website GitHub

Re: etc_query: all things Textpattern

colak wrote #321297:

This is way beyond what I expected txp to do out of the box!!! I cannot even pretend that I understand the syntax, but I am incredibly impressed.

Textpattern is a magic wand, but the wizardry is yours. A quick regex introduction will completely demystify the trick.

Offline

#332 2020-01-23 17:51:01

etc
Developer
Registered: 2010-11-11
Posts: 5,675
Website GitHub

Re: etc_query: all things Textpattern

Bloke wrote #321298:

I’ll add that example to the docs for the excerpt tag.

Wouldn’t it fit better as new global replace attribute example (since we have to document it anyway)?

Offline

#333 2020-01-23 17:59:38

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,443
Website GitHub

Re: etc_query: all things Textpattern

etc wrote #321301:

Wouldn’t it fit better as new global replace attribute example (since we have to document it anyway)?

Sure, we can add something similar there too. Or maybe another type of example. Just thought it’d be nice for people who are looking to excerpt an article to see there are a few ways to do it without having to use the tag itself.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Hire Txp Builders – finely-crafted code, design and Txp

Offline

#334 2020-01-23 18:03:07

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,443
Website GitHub

Re: etc_query: all things Textpattern

Question: for documentation purposes, does replace only work to replace stuff matched by trim or can it be used on its own?


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Hire Txp Builders – finely-crafted code, design and Txp

Offline

#335 2020-01-23 18:12:50

etc
Developer
Registered: 2010-11-11
Posts: 5,675
Website GitHub

Re: etc_query: all things Textpattern

Bloke wrote #321304:

Question: for documentation purposes, does replace only work to replace stuff matched by trim or can it be used on its own?

Hmm, what could it replace without trim? If you see…

Edit: probably replace is misleading. What is the opposite of trim?

Offline

#336 2020-01-23 18:32:39

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,443
Website GitHub

Re: etc_query: all things Textpattern

etc wrote #321305:

Hmm, what could it replace without trim? If you see…

I figured as much. Just wasn’t sure if the regex syntax could be used like sed with /find/replace/g. But that’s probably pushing it!

I agree that trim/replace isn’t the most obvious pairing but can’t think of anything else.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Hire Txp Builders – finely-crafted code, design and Txp

Offline

#337 2020-01-23 19:24:19

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

Re: etc_query: all things Textpattern

Maybe it should go to as many places as possible. This is so much of a brilliant example for so many places:

  • replace
  • trim
  • excerpt.
  • body

For the third we could have an example like

<txp:if_excerpt>
	<txp:excerpt />
<txp:else />
	<txp:body escape="tags" trim="/^\W*((?:\w+\W+){35})\w.*$/s" replace="$1&hellip;" />
</txp:if_excerpt>

It may be a good idea to also link to the regex intro recommended by Oleg, possibly in the trim page. Finally as it is basically using the body tag, can we actually leave it out of there? :)


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#338 2020-01-23 19:33:53

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

Re: etc_query: all things Textpattern

etc wrote #321305:

probably replace is misleading. What is the opposite of trim?

augment, expand, extend, complete, …

augment sounds ok but it’ might be a lot to type and its very prone to typos:)


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#339 2020-01-23 20:03:23

singaz
Member
Registered: 2017-03-12
Posts: 150

Re: etc_query: all things Textpattern

colak wrote #321297:


We should add the above in the docs under the body and excerpt as it seems to be of use for many.

Add absolutely necessary!!!

Often needed function


Sorry my horror English. I’m learning textpattern, I’m learning English

Offline

#340 2020-01-23 21:50:46

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,443
Website GitHub

Re: etc_query: all things Textpattern

The only thing that kinda makes sense, besides find/replace is cut/replace, but since we already have ‘trim’ that makes it a tad tricky, unless we allow overlap of the new ‘cut’ and phase out ‘trim’ in a few versions.

Not sure. But I can live with trim/replace.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Hire Txp Builders – finely-crafted code, design and Txp

Offline

#341 2020-01-24 00:08:55

singaz
Member
Registered: 2017-03-12
Posts: 150

Re: etc_query: all things Textpattern

The \A([\w\s].{5,25}) expression works here .
The
<txp:excerpt escape="tags" trim="/\A([\w\s].{5,25})" replace="$1&hellip;" />
<txp:excerpt escape="tags" trim="\A([\w\s].{5,25})" replace="$1&hellip;" />
expression on the site does not work.

XPath + regexp = conflict.
Or I do not understand.

A limited number of characters without a plugin so far does not work.


Sorry my horror English. I’m learning textpattern, I’m learning English

Offline

#342 2020-01-24 07:47:45

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 5,192
Website GitHub

Re: etc_query: all things Textpattern

singaz wrote #321315:

The \A([\w\s].{5,25}) expression works here .
The
<txp:excerpt escape="tags" trim="/\A([\w\s].{5,25})" replace="$1&hellip;" />
<txp:excerpt escape="tags" trim="\A([\w\s].{5,25})" replace="$1&hellip;" />
expression on the site does not work.

XPath + regexp = conflict.

Things may be getting confusing here. Just to clarify:

  • This new feature does not require etc_query
  • As of now, it will only work with the very latest txp v.4.80 development version from here, i.e. since yesterday. It won’t work on an earlier version of txp.

To your question. Try either: /\A([\w\s].{5,25})/s or /^\A([\w\s].{5,25})$/s as the attribute.

An attempt at an explanation (Stef/Oleg, please correct this if I’m wrong): as far as I can tell from the textpattern code, if you want to use a regex replace (which uses the php preg_replace function), you need to enclose your search pattern in a pair of bounding characters, e.g. / ... / (possibly also with ^ string-begin and $ string-end markers). Otherwise it will try and do a normal from-to text replace. The /s at the end is a so-called PCRE string modifier (as detailed here).

The regex101.com site tries to make things look nice for you and places the beginning and end bounding characters and string-modifiers to either side (it does explain it in the sidebar) but you still need them in your trim="…" attribute.


TXP Builders – finely-crafted code, design and txp

Offline

#343 2020-01-24 10:14:10

etc
Developer
Registered: 2010-11-11
Posts: 5,675
Website GitHub

Re: etc_query: all things Textpattern

singaz wrote #321315:

A limited number of characters without a plugin so far does not work.

You probably need to extend your pattern till the end of the string:

<txp:excerpt escape="tags" trim="/\A([\w\s].{5,25}).*$/s" replace="$1&hellip;" />

Offline

#344 2020-01-24 12:07:35

singaz
Member
Registered: 2017-03-12
Posts: 150

Re: etc_query: all things Textpattern

Updated to today’s version and it worked.

To work with the Cyrillic alphabet (and others) need to write this:

<txp:excerpt escape="tags" trim="/\A([\p{L}\p{N}].{5,28})\s.*$/s" replace="$1&hellip;" />


Sorry my horror English. I’m learning textpattern, I’m learning English

Offline

#345 2020-01-24 12:12:28

singaz
Member
Registered: 2017-03-12
Posts: 150

Re: etc_query: all things Textpattern

It already works, and it is good. But the number of words and characters in the lists is different.
Looking for a reason.


Sorry my horror English. I’m learning textpattern, I’m learning English

Offline

Board footer

Powered by FluxBB