Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#25 2018-11-14 17:09:31

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

Re: article_custom from both categories (AND)

jakob wrote #315231:

I’m not sure I’ve understood the dot item separator in breakby, though. What does that mean?

Just to make difference between Category1="something", Category2="" and Category1="", Category2="something". Can be replaced by any separator improbable in category names, or removed if there is no chance of confusion.

Offline

#26 2018-11-15 11:00:19

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,243
Website GitHub

Re: article_custom from both categories (AND)

One more subtlety to the OP: client decided to collapse the h2/h3 tags into a single ‘h2 (location)’ format, and only wanted to output a table if there were articles in that category, i.e. completely omit one or more of the tables if it contains no articles. <txp:evaluate> to the rescue:

...
<txp:evaluate test="article_custom">
   <h2><txp:category title /> (<txp:variable name="t_location" />)</h2>
   <ul class="stocktable">
      <txp:article_custom id='<txp:variable name="location_ids" />' ... >
...
      </txp:article_custom>
   </ul>
</txp:evaluate>

I loooooooove the flexibility and power in 4.7, woot!


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

#27 2018-11-15 11:44:34

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

Re: article_custom from both categories (AND)

Bloke wrote #315252:

I loooooooove the flexibility and power in 4.7, woot!

Re flexibility… wouldn’t this work too (though not exactly the same way)?

<txp:article_custom wraptag="ul" class="stocktable"
    labeltag="h2" label='<txp:category title /> (<txp:variable name="t_location" />)'  ... 
>
...
</txp:article_custom>

Offline

#28 2018-11-15 12:18:30

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,243
Website GitHub

Re: article_custom from both categories (AND)

etc wrote #315254:

Re flexibility… wouldn’t this work too (though not exactly the same way)?

Probably! Good idea: since the client has simplified things it might mean I can make optimisations elsewhere. I’ll give it a go, thank you.


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

#29 2018-11-15 22:09:31

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

Re: article_custom from both categories (AND)

Breaking article lists via breakby/breakform is taking shape. That’s how outputting articles in category tables works at present:

<txp:article_custom sort="Category1, Category2" limit="999"
    breakby="bycat12" breakform="catbreak"
>
    <txp:variable name="count" add />
    <tr>
        <td><txp:permlink><txp:title /></txp:permlink></td>
        <td><txp:category1 title /></td>
        <td><txp:category2 title /></td>
    </tr>
</txp:article_custom>

bycat12 form:

<txp:category1 />,<txp:category2 />

catbreak form:

<txp:if_different><h2><txp:category1 title /></h2></txp:if_different>
<h3><txp:category2 title /> [<txp:variable name="count" reset="0" />]</h3>
<table>
    <thead><tr><th>Title</th><th>Category 1</th><th>Category 2</th></tr></thead>
    <tbody><+></tbody>
</table>

Offline

#30 2018-11-16 21:46:42

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,577
Website

Re: article_custom from both categories (AND)

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

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…


TXP Builders – finely-crafted code, design and txp

Offline

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

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

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.

Offline

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

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,243
Website GitHub

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: 5,028
Website GitHub

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.

Offline

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

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,243
Website GitHub

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: 5,028
Website GitHub

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.

Offline

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

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,243
Website GitHub

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

Board footer

Powered by FluxBB