Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#13 2018-11-10 16:54:11

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

Re: article_custom from both categories (AND)

Bloke wrote #315155:

the trick is coming up with a suitable syntax.

As always. If I understand your OP requirement, we need

Category1='location' AND Category2='type'

A right syntax here could be

match="(Category1, Category2)" category="(location, type)"

but what to do then with

match="(Category1, Category2)" category="(location, type, something), else"

Offline

#14 2018-11-10 16:59:02

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

Re: article_custom from both categories (AND)

Bloke wrote #315156:

As a little further addendum I’d like to display how many articles are in the stock section that are not SOLD and show it in the article title of the stocklist.

Not sure to understand where you want it, but pgonly should work:

<txp:article_custom pgonly pageby="1" limit="999" price="SOLD" exclude="price" ... />

Offline

#15 2018-11-10 17:39:56

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

Re: article_custom from both categories (AND)

Sorry I wasn’t clear. I want it to display the article count in the article title itself. Can we parse PHP code or tags in the article title field?

EDIT: I guess not, since dynamically changing the title might cause problems. I can always do it in the excerpt instead I suppose – I’ll just need a(nother) exception in my page-handling template.

Last edited by Bloke (2018-11-10 17:41:15)


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

Online

#16 2018-11-10 18:20:58

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

Re: article_custom from both categories (AND)

You mean a title like Welcome to <txp:site_name />!? This will be parsed when output by <txp:title escape="" />, but only on the second pass. And the context on the second pass can be different.

Edit: this said, nothing stops us from adding parse to possible escape values, but I’m not sure <txp:php /> should be eligible for parsing.

Offline

#17 2018-11-11 08:44:52

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

Re: article_custom from both categories (AND)

etc wrote #315160:

nothing stops us from adding parse to possible escape values, but I’m not sure <txp:php /> should be eligible for parsing.

Agreed. It’s fine as it is. I went with using the excerpt in the end and used another article custom call. Seems to work well.

I absolutely love working with the new tags in 4.7. So much scope for more natural and flexible tag structures. Thank you for all your help.


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

Online

#18 2018-11-12 16:30:29

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

Re: article_custom from both categories (AND)

Bloke wrote #315143:

I tried to do it in one giant article_custom call sorted by category2,category1 and then use if_different to show the headings but things fall apart when constructing the end table/tbody in the loop.

This difficulty has inspired test attribute of <txp:if_different />. In 4.7.2 the following should work (can be simplified if the counts are not needed):

<txp:variable name="thead">
  <thead>
    <tr>
      <th>Serial number</th>
      <th>Year</th>
      <th>Condition</th>
      <th>Price</th>
    </tr>
  </thead>
</txp:variable>

<txp:article_custom sort="Category1, Category2" limit="999">
  <txp:if_different test='<txp:category1 />.<txp:category2 />'>
    <txp:if_first_article not>
      <h3><txp:variable name="cat2" /> [<txp:variable name="count" />]</h3>
      <table><txp:variable name="thead" /><txp:variable name="table" wraptag="tbody" /></table>
    </txp:if_first_article>
    <txp:if_different><h2><txp:category1 title default="Untitled" /></h2></txp:if_different>
    <txp:variable name="cat2" value='<txp:category2 title default="Untitled" />' />
    <txp:variable name="count" value="0" />
    <txp:variable name="table" value="" />
  </txp:if_different>

  <txp:variable name="count" add />
  <txp:variable name="table">
    <txp:variable name="table" />
    <tr>
      <td><txp:custom_field name="Serial number" /></td>
      <td><txp:custom_field name="Year" /></td>
      <td><txp:custom_field name="Condition" /></td>
      <td><txp:custom_field name="Price" /></td>
    </tr>
  </txp:variable>

  <txp:if_last_article>
    <h3><txp:variable name="cat2" /> [<txp:variable name="count" />]</h3>
    <table><txp:variable name="thead" /><txp:variable name="table" wraptag="tbody" /></table>
  </txp:if_last_article>
</txp:article_custom>

Offline

#19 2018-11-13 00:00:24

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

Re: article_custom from both categories (AND)

etc wrote #315176:

This difficulty has inspired test attribute of <txp:if_different />.

Now that’s cool! 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. This approach wraps it up fairly neatly without needing all the extra variable baggage. Hats off to you, Sir.

I expect this will also help with making nested <ul> / <li> constructs, which is another tricky puzzle to do neatly in a loop.


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

Online

#20 2018-11-13 11:02:17

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

Re: article_custom from both categories (AND)

While I’m not sure I fully understood that last example (the counts have got me) it would be great to have solutions for the two things you mentioned in this thread. They’ve been common problems in the past, and some have required other plugins up to now:

  • Matching against combinations of categories (also custom_fields?!)
  • Handling if_first_article and if_last_article so that they don’t affect if_different when creating lists interspersed with headings.
    For the latter I’ve tried complex tricks with variables, hiding empty tags at the beginning with the :empty CSS selector or even wrapping the whole thing in a rah_replace or similar to search and replace out leftover empty tags in the output.

I’d love to see these new/extra attributes make those problems a thing of the past.


TXP Builders – finely-crafted code, design and txp

Offline

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

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

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.

Offline

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

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

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

Online

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

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

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.

Offline

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

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,578
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

Board footer

Powered by FluxBB