Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

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

singaz
Member
From: Kyiv, Ukraine
Registered: 2017-03-12
Posts: 143

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

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
From: Kyiv, Ukraine
Registered: 2017-03-12
Posts: 143

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
From: Kyiv, Ukraine
Registered: 2017-03-12
Posts: 143

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

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

#349 2020-01-24 14:43:50

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

Re: etc_query: all things Textpattern

Karsten wrote #321327:

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.

You might want to do it on article save, via a plugin, to avoid content manipulation on each site access.

Offline

#350 2020-01-24 15:52:08

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

Re: etc_query: all things Textpattern

Didn’t know there was a plugin that could do that, but it wouldn’t change the hundreds of articles already in the website. But also, we use different formats of our content for different purposes, depending on what I need I use the rah_replace tool to re-format it to fit the specific need on that particular page.

Also I use it for some other things, for example, in Dutch we use a comma for decimals instead of full stop. So on the page I want it to say €20,00 but I use a bit of PHP to dynamically recalculate the price. This allows me for example to set a 25% discount on a group of products, the Rah_replace tool switches the comma for a . enabling me to re-calculate the price [20.00 × 0.75 = answer] > Get it 25% off, for only [echo answer].

There’s probably better ways to do it, but as I said, I’m not a coder, and this works, so I happy :)

Offline

Board footer

Powered by FluxBB