Textpattern CMS support forum

You are not logged in. Register | Login | Help

#31 2018-11-17 10:50:09

etc
Developer
Registered: 2010-11-11
Posts: 2,949
Website

Re: article_custom from both categories (AND)

jakob wrote #315330:

I like it! Will that be in 4.7.2, then?

Thanks! It is in dev in any case, testers welcome.

One question: is it necessary that breakby is also a separate form? That would mean there are three forms attached to single article_custom tag, which could get unruly on larger or more complex sites…

One still can set breakby="<txp:category1 />,<txp:category2 />" (in double quotes), but I find the form approach more robust, since e.g. breakby='<txp:category1 />,<txp:category2 />' (in single quotes) will not work as expected. And actually breakby form is likely to be reused in breakform, as in

<txp:if_different test='<txp::bycat12 />' />
New entry
</txp:if_different>
...

so for complex sites it’s rather a feature.


etc_[ query | search | pagination | date | tree | cache ]

Offline

#32 2018-12-06 11:52:19

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 8,458
Website

Re: article_custom from both categories (AND)

I have another query about this. Does escape work in conditional tags? My tests indicate it does not, but I may be missing something.

Use case (and there may be a better way to do this)…

1) I have a section with all articles for sale in it, as mentioned above.
2) I want to make a more specific section that pulls from the main section of all things for sale, but only if they match certain criteria.
3) The criteria in this case is “Does the Model custom field begin with the same sequence of letters as the Section?”

Let’s take cars as an example. I have all Volkswagen cars listed for sale, broken down by location at /volkswagen.

Each car article has a Model custom field that might be “Golf GTI” or “Polo” or “Up! 1.4l” or “Golf R”, or “Golf GTD” or something.

I want the url /golf to only pull out the articles that match the start of the Model custom field with the section (and yes I’d love to do /volkswagen/golf/… but meh, not fighting gbp_permanent_links).

I can’t figure out how to match the custom field directly in the <txp:article_custom> tag with Model='...' so I fell back on the inefficient method of extracting them all with limit="999" and then in the container doing:

<txp:if_custom_field name="Model" match="pattern" value='^<txp:variable name="this_section" />.*$'>
   Yay, display this article.
</txp:if_custom_field>

Where the “this_section” variable has previously been set outside the article_custom to represent the fake section name.

But the above doesn’t match. I assume it’s falling foul of case sensitivity because the section name is lower case and the Model isn’t. Can’t figure out how to add the /i switch (don’t think it’s possible). So I tried escape="lower" in the <txp:if_custom_field /> tag: no dice.

Is there a neat way of doing this? Can <txp:evaluate /> come to the rescue? I’ve probably missed something obvious.


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

#33 2018-12-06 12:15:13

etc
Developer
Registered: 2010-11-11
Posts: 2,949
Website

Re: article_custom from both categories (AND)

Bloke wrote #315501:

Does escape work in conditional tags?

Yes, but not the way one might expect. Global attributes are applied (mainly) to tags output, not when tags are processed. So

<txp:if_custom_field name="Model" value="golf" escape="lower">
    It's a Golf!
<txp:else />
    No Golf here.
</txp:if_custom_field>

will output it's a golf! or No Golf here., but will not lowercase Model field value for comparison. There is (almost) no way a global attribute could intervene in tags internal processing.

You could probably try ^(?i)<txp:variable name="this_section" />(?-i).*$ pattern, though I’m not sure it works in PHP.


etc_[ query | search | pagination | date | tree | cache ]

Offline

#34 2018-12-06 12:19:47

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 8,458
Website

Re: article_custom from both categories (AND)

etc wrote #315503:

Global attributes are applied (mainly) to tags output, not when tags are processed.

That’s what I figured, thanks for the sanity check.

You could probably try ^(?i)<txp:variable name="this_section" />(?-i).*$ pattern, though I’m not sure it works in PHP.

It does! Wow, didn’t know that was possible. Thank you so much.


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

#35 2018-12-06 12:24:03

etc
Developer
Registered: 2010-11-11
Posts: 2,949
Website

Re: article_custom from both categories (AND)

Yeah, nice to know. Pity though, that we can not (?) do the filtering on <txp:article /> level, that would be much better.


etc_[ query | search | pagination | date | tree | cache ]

Offline

#36 2018-12-06 12:30:31

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 8,458
Website

Re: article_custom from both categories (AND)

etc wrote #315507:

Pity though, that we can not (?) do the filtering on <txp:article /> level, that would be much better.

Yes, that’s one of the things I want to address when we handle custom fields better. Hopefully, when we introduce a name/title split for custom fields so we’re not hamstrung by the “no spaces” thing, we can also beef up the matching capabilities of article(_custom).

We have a match attribute already but it’s limited to categories, afair.


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

#37 2018-12-06 13:07:43

etc
Developer
Registered: 2010-11-11
Posts: 2,949
Website

Re: article_custom from both categories (AND)

Actually, if your db collation is case insensitive (UTF8_GENERAL_CI or such), this should work:

<txp:article_custom Model='<txp:variable name="this_section" />%' />

etc_[ query | search | pagination | date | tree | cache ]

Offline

#38 2018-12-06 13:27:10

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 8,458
Website

Re: article_custom from both categories (AND)

etc wrote #315509:

Actually, if your db collation is case insensitive

Ha! Swear I tried that. But yes that’s perfectly acceptable and way more performant. Thank you again.


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