Textpattern CMS support forum

You are not logged in. Register | Login | Help

#21 2018-11-14 15:02:47

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

Re: article_custom from both categories (AND)

Bloke wrote #315181:

I always tie myself up in knots trying to do that kind of thing because you need to handle the ‘end previous table, start next table’ case first… but only if not the first time, and then handle the closing table as a special case at the end.

Metoo… but test alone does not solve it, unfortunately, though simplifies the construction.

jakob wrote #315190:

it would be great to have solutions for the two things you mentioned in this thread.

  • Matching against combinations of categories (also custom_fields?!)

We have a branch for things like this, awaiting 4.8.


  • Handling if_first_article and if_last_article so that they don’t affect if_different when creating lists interspersed with headings.

I think that the right concept for wrapped lists is breakform and not if_different. Still testing, but that’s how it works for me atm. We pass to <txp:article(_custom) /> a parseable breakby attribute that will be evaluated on each loop. As soon as its value changes, the accumulated block is injected (as <+> replacement that we already use in wraptag) into breakform. Additionally, the variables with reset attribute are reset to its value.

The following will output articles in tables grouped by (Category1, Category2), with headings and counts:

<txp:article_custom sort="Category1, Category2"
    breakby="<txp:category1 />.<txp:category2 />" breakform="catbreak"
>
    <txp:variable name="count" reset="0" add />
    <tr>
        <td><txp:permlink><txp:title /></txp:permlink></td>
        <td><txp:custom_field name="custom1" /></td>
        <td><txp:custom_field name="custom2" /></td>
    </tr>
</txp:article_custom>

catbreak form:

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

This solves the OP problem. I would love to hear whether this is comprehensible enough to be continued.


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

Offline

#22 2018-11-14 16:15:14

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

Re: article_custom from both categories (AND)

etc wrote #315222:

I think that the right concept for wrapped lists is breakform and not

I agree. <txp:if_different> is fine for linear parsing, but when creating blocked or nested content, it’s cumbersome and non-intuitive.

I would love to hear whether this is comprehensible enough to be continued.

Hell yes. I like that it reuses the <+> replacer to inject the body content because it neatly sidesteps having to do linear checking by batching up content in chunks. breakby and breakform are worthy poweruser additions to the tag arsenal.

smd_calendar used a similar concept (though very scrappily done) to render cell content using forms for each cell and header so you could build your own calendar layouts. I intended the next step up to use wraptag to construct the calendar without enforcing table tags on everyone but I never got round to it. My guess is this native use of breakby/breakform could reduce the smd_calendar plugin code by half!


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

#23 2018-11-14 16:41:05

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

Re: article_custom from both categories (AND)

Bloke wrote #315224:

My guess is this native use of breakby/breakform could reduce the smd_calendar plugin code by half!

I would love to make them global, but don’t know how. Currently core has no means to interfere in the tags processing (lAtts() is the only common entry point), so the tags have to do (at list a part of) the job themselves. There is a vague hope to delegate the main job to the bodyless <txp:if_different /> and doWrap(), but it’s easy to mess up as always with globals.

Currently I have done something only for <txp:article(_custom) />, can commit for testing.


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

Offline

#24 2018-11-14 17:01:39

jakob
Moderator
From: Germany
Registered: 2005-01-20
Posts: 3,156
Website

Re: article_custom from both categories (AND)

I like the idea too :-) and like the breakform with the replace item as used in wraptag. I’m not sure I’ve understood the dot item separator in breakby, though. What does that mean?


TXP Builders – finely-crafted code, design and txp

Offline

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

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

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.


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

Offline

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

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

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: 2,947
Website

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>

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

Offline

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

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

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: 2,947
Website

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>

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

Offline

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

jakob
Moderator
From: Germany
Registered: 2005-01-20
Posts: 3,156
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

Board footer

Powered by FluxBB