Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#331 2020-01-23 17:48:07
Re: etc_query: all things Textpattern
Offline
#332 2020-01-23 17:51:01
Offline
#333 2020-01-23 17:59:38
Re: etc_query: all things Textpattern
etc wrote #321301:
Wouldn’t it fit better as new global
replaceattribute 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
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
Re: etc_query: all things Textpattern
Bloke wrote #321304:
Question: for documentation purposes, does
replaceonly work to replace stuff matched bytrimor 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
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
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:
replacetrimexcerpt.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…" />
</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
Re: etc_query: all things Textpattern
etc wrote #321305:
probably
replaceis misleading. What is the opposite oftrim?
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
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…" />
<txp:excerpt escape="tags" trim="\A([\w\s].{5,25})" replace="$1…" />
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
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…" />
<txp:excerpt escape="tags" trim="\A([\w\s].{5,25})" replace="$1…" />
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
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…" />
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