Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

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

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,090
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,090
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: 11,446
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.

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: 4,726
Website

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,187
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

#346 2020-01-24 13:10:24

Karsten
Member
From: Leiden, Netherlands
Registered: 2011-04-24
Posts: 47
Website

Re: etc_query: all things Textpattern

Not being a coder, do I understand correctly that these are regular expressions used in native TXP codes? (in the dev version currently) That is really cool.

I now use the rah_replace plugin a lot to manipulate/style contents, or make things uniform. This is particularly handy if you have multiple people posting content.

Offline

#347 2020-01-24 13:17:36

Karsten
Member
From: Leiden, Netherlands
Registered: 2011-04-24
Posts: 47
Website

Re: etc_query: all things Textpattern

It would also be really cool to be able to use reg. expressions in conditional tags.

I work a lot with Indesign and use reg. expressions in my paragraph styles. This allows me, for example, to change the font if particular symbols are used. So for example, not all fonts work well with Cyrillic or Arabic, so I use reg. expressions to find certain ranges of unicode symbols and if present apply a different font to those characters that is more suited for them.

Offline

#348 2020-01-24 14:28:31

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

Re: etc_query: all things Textpattern

Karsten wrote #321328:

Not being a coder, do I understand correctly that these are regular expressions used in native TXP codes? (in the dev version currently)

Yes, you can trim/replace the output of any tag this way.

It would also be really cool to be able to use reg. expressions in conditional tags.

Probably, but it makes many tags to patch. An alternative way is to register functions like match=preg_match, replace=preg_replace for use in <txp:evaluate />. Then you will be able to test

<txp:evaluate query='match("/something/i", <txp:body escape="quote" />)'>
    There is something in my body.
<txp:else />
    Nothing.
</txp:evaluate>

Not that it’s better than <txp:php />, but requires only txp code.

Offline

Board footer

Powered by FluxBB