Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#25 2020-09-22 09:35:49

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

Re: Categories list here, related article output over there

etc wrote #326001:

Probably a typo: <txp:if_section section="default"> should be <txp:if_section name="default">.

Sorry, my bad! If you split the code into two templates as above, this bit of code is irrelevant… (I updated the earlier post and noted the edit).


TXP Builders – finely-crafted code, design and txp

Offline

#26 2020-09-22 12:46:28

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,912
Website

Re: Categories list here, related article output over there

I think we’re almost there.

This is pretty slick… and abstract. If I ever knew that before, I certainly would not have fingered it now. I peaked with Textpattern in 2010.

. . .
<txp:if_category>
  <txp:hide>
     Filtered list of articles by category magically appears here.
  </txp:hide>
<txp:else />
  <txp:hide>
     Full list of glossary articles magically appears here.
  </txp:hide>
</txp:if_category>
. . .
jakob wrote #326000:

The principle is:

  • txp:article with listform outputs a list. If some filtering criteria is active in the url – e.g. category, author, time etc. – the list is filtered automagically.
  • txp:article with form does the individual article bit.

I will try not to forget it all in three days. I’m leaving those comments in the code. ;)

The if_article_list bit in the code is only to alternate the title if you’re on a category filtering page.

What does alternate the title mean?

In any case, that all works as prescribed — thanks big time Julian — but there’s one wrench in the conceptual cog yet…

If you recall, the full glossary list is supposed to be output in alphabetical sections, I mentioned that in a previous code example. Here it is again…

<section id="a" class="terms">
    <h2>A</h2>
    <txp:article_custom category="a" 
                        sort="Title"
                        wraptag="ol" 
                        class="termslist" 
                        break="li" 
                        form="terms_alphabetical" />
  </section>
  <txp:hide>Blocks B through Z not shown here</txp:hide>

The only reason I used article_custom, not because I knew what I was doing, but because I thought if you needed more than one list of articles to output, then you needed to use article_custom each time.

Do you see the pattern? When the ‘Glossary’ link in main nav is clicked, they should get the full glossary set of articles, but the articles will be presented in <section>s by alphabetical letter:

  • A
  • B
  • C
  • etc.

Last edited by Destry (2020-09-22 13:20:05)

Offline

#27 2020-09-22 12:56:37

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,912
Website

Re: Categories list here, related article output over there

I will try it using just article tags and see if it grabs.

Offline

#28 2020-09-22 13:00:56

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

Re: Categories list here, related article output over there

I think you excerpted a bit too much in your code block there (if_article_list doesn’t have those attributes and if_category is not responsible for filtering)?

The principle is txp:article does the automagic filtering according the context specified in the url, e.g. /glossary/?c=category-name (or /glossary/?author=destry etc.). If there’s no context it outputs the entire list (afterthought: you need to add a high limit="9999" attribute if you want a lot on one page).

Destry wrote #326013:

What does alternate the title mean?

All the txp:if_category tag does in my example above is do:

  • if this is a category page, show me the “Entries under {category title here}” heading with the current category title inserted … else …
  • if this isn’t a category page, show me the “Full glossary” heading.

I peaked with Textpattern in 2010.

I don’t think so, seeing as you wrote the long-time-definitive article on txp building blocks :-)


TXP Builders – finely-crafted code, design and txp

Offline

#29 2020-09-22 13:09:02

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

Re: Categories list here, related article output over there

Destry wrote #326013:

If you recall, the full glossary list is supposed to be output in alphabetical sections, I mentioned that in a previous code example. Here it is again…

<section id="a" class="terms">...

The only reason I used article_custom, not because I knew what I was doing, but because I thought if you needed more than one list of articles to output, then you needed to use article_custom each time.

I knew there must be something to complicate the matter ;-)

You’re right, if you use txp:article_custom, you’ll need to include section="glossary" as Oleg said and if you’re on a category page, you’ll need category='<txp:category />' too (with single quotes for tag-in-tag output).

I think there was a newer matching method that Oleg pointed out once before. Oleg was that just with category (just the word) as an attribute, or with match="…". I’ve forgotten.

I vaguely remember now that there was an old post on that somewhere. I’m wondering whether you might be able to get around the whole 26 sets of article_custom tags by using txp:if_different in the listform you specify for txp:article, i.e. have the initial letter appear as interim headings. I must have a think about that.


TXP Builders – finely-crafted code, design and txp

Offline

#30 2020-09-22 13:12:25

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,912
Website

Re: Categories list here, related article output over there

jakob wrote #326017:

I think you excerpted a bit too much in your code block there…

Gah. Quite right. (FIXED). But it’s not that way in my page. Forum editing is tiring. More effort has gone into just trying to communicate the idea than anything else. :{

So, getting back to my ‘alphabetical set of lists’ issue, if I do this…

. . .
<txp:else />
<section id="a" class="terms">
  <h2>A</h2>
  <txp:article_custom category="a" 
       sort="Title"
       wraptag="ol" 
       class="termslist" 
       break="li" 
       form="terms_alphabetical" />
</section>
<section id="a" class="terms">
  <h2>B</h2>
  <txp:article_custom category="b" 
       sort="Title"
       wraptag="ol" 
       class="termslist" 
       break="li" 
       form="terms_alphabetical" />
</section>
. . . etc . . .

Instead of just leave it with the default empty nothing…

<txp:hide>Full list of glossary articles magically appear here.</txp:hide>

Then the output is the full glossary twice:

  1. once with the alphabetical section lists as desired
  2. once with the the full glossary list without sections

I can see how that is happening now, but I only want the first situation.

Last edited by Destry (2020-09-22 13:20:53)

Offline

#31 2020-09-22 13:23:40

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

Re: Categories list here, related article output over there

jakob wrote #326018:

I’m wondering whether you might be able to get around the whole 26 sets of article_custom tags by using txp:if_different in the listform you specify for txp:article, i.e. have the initial letter appear as interim headings. I must have a think about that.

Oleg to the rescue: he made a very neat suggestion here using txp:if_different.

Transferring that to your case, in your txp:article tag, you’d need sort="UPPER(Title)" instead of sort="Title" in the code above.

Then in your listform, you’d have:

    <txp:if_different>
        <h2 id="<txp:evaluate query='substring(<txp:title escape="quote" />, 1, 1)' escape="lower" />"><txp:evaluate query='substring(<txp:title escape="quote" />, 1, 1)' escape="upper" /></h2>
    </txp:if_different>
    <h3><txp:permlink><txp:title /></txp:permlink></h3>

For clarity, that should give you this kind of output:


<h2 id="a">A</h2>
<h3><a href="glossary/aadvark">Aardvark</a></h3>
<h3><a href="glossary/abacus">Abacus</a></h3>
…
<h2 id="b">B</h2>
<h3><a href="glossary/behemoth">Behemoth</a></h3>
<h3><a href="glossary/bricolage">Bricolage</a></h3>
…
<h2 id="c">C</h2>
…

If you want h3 + ul list + h3 + ul-list, you’ll have to investigate Oleg’s more complex example using breakby. Alternatively don’t use a list (ol isn’t the right type here anyway) and save yourself the pain fun.

That hopefully solves the interim glossary initial headings in the list of terms that are output and gives each an “id”. The a-z nav bar is still to be done.


TXP Builders – finely-crafted code, design and txp

Offline

#32 2020-09-22 13:47:24

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,912
Website

Re: Categories list here, related article output over there

For the sake of being thorough, I really liked Oleg’s solution for a related problem to the glossary list that I was eventually going to come back to, which was to use a Write panel field (he used Keywords, but you could use a custom field) for a comma-separated list of ‘synonymous’ glossary terms, and these would be added as non-linked glossary entries with a ‘see [primary term]’ link in parentheses.

The idea was that there’s one primary article entry for a term, then all other related terms (e.g. colloquialisms, cultural differences, and in this case the same terms in French) are accounted for in the same article. The value of this in the back is to keep article overhead down, and in the front, to help direct people with different mental models to the term that has the definition.

Ex:

B
D
P
  • Porte-foret (see Drill)
V
  • Vilebrequin (see Brace)
  • . . .

Oleg has a blog post on it. That was some years back. Don’t know if that is possible now or if Txp is now capable of doing it natively, but it’s still highly desired in this project, and in relation to the full glossary list of alphabetically sectioned terms.

The original idea was to have the glossary appear in the homepage (because the whole site was the glossary), but that’s when the scope was only on traditional tools. I’ve since added terms for other groups (trees, timber, trades, people…). So now it makes sense to have the categories as discussed in this thread. Otherwise, same concept as originally imagined. The architecture is just a little different.

I’ll have to dig up the related posts, but I’m called to other duties now. Will be back later.

(The French thing will make more sense when you see an example of the site. It’s not a bilingual site, exactly; rather, most of my research was done using French literature and tools, so there’s simply a terms equivalent in French, and the editing is done from a native English speaker living in France. All part of the backstory.)

Had them bookmarked, in fact. In case you want more context:

Last edited by Destry (2020-09-22 14:14:22)

Offline

#33 2020-09-22 14:13:40

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

Re: Categories list here, related article output over there

Ah, I forgot all about that but now you mention it, it rings a bell. Sounds extremely clever and your project sounds fascinating too. Going to have to press on with my French lessons, I guess.


TXP Builders – finely-crafted code, design and txp

Offline

#34 2020-09-22 14:20:53

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,101
Website GitHub Mastodon Twitter

Re: Categories list here, related article output over there

jakob wrote #325986:

Hi Yiannis. I saw what you wrote before but I didn’t understand it 😳. I had read it as iterating over 10 articles in the glossary section ignoring forms but including the category_list each time? But maybe it’s a new trick I’ve not grocked yet.

Maybe I am misunderstanding but if the categories are enclosed into an article custom tag pointing to a section, their urls will follow the /section/category/ schema. If they are in the front page they may either link to ?c=trees or /default/trees/.


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#35 2020-09-22 22:54:26

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,912
Website

Re: Categories list here, related article output over there

jakob wrote #326020:

Oleg to the rescue: he made a very neat suggestion here using txp:if_different.

. . .

If you want h3 + ul list + h3 + ul-list, you’ll have to investigate Oleg’s more complex example using breakby.

I’m trying the latter approach because I want more layout control (as it works with my flexbox setup) over the glossary links as list items rather than headings. See markup below.

(ol isn’t the right type…)

I’m not arguing because I don’t have the specs memorized, but if a list is in alphanumeric order, doesn’t that make it an ordered list? That was my thinking. If I wanted lists in random order, then ul would seem to make sense, but if they need to be in a specific order, that seems like a job for ol. I’m happy to make it unordered if my logic is faulty.

That hopefully solves the interim glossary initial headings in the list of terms that are output and gives each an “id”. The a-z nav bar is still to be done.

I’m not interested in having a ‘a-z nav bar’ at this point, but I’ll keep that notion on ice. The glossary is written for people who don’t know what all the tools are or what they would be called — beginners, starting with me — so such a sub-nav would have limited utility anyway for that audince. And I want to encourage scrolling/scanning the list rather than blind-jumping around. I guess the ids in the heading don’t matter either, then.

As for solving the initial lettered headings, however, I think we’re almost there, but it’s not mapping out as you suggested anywhere.

Here are the relevant files in play…

Default (home) template:
<txp:category_list parent="groups" 
                   exclude="groups" 
                   wraptag="ol" 
                   break="li" 
                   class="">
<a href="<txp:site_url />glossary/?c=<txp:category />"><txp:category title /></a>
</txp:category_list>
Glossary template:
<txp:if_article_list>
    <txp:if_category>
        <h1 class="titre">Glossary</h1>
        <h2>Entries under <txp:category title /></h2>
        <txp:hide>Filtered list of articles magically appear here.</txp:hide>
    <txp:else />
        <h1 class="titre">Glossary</h1>
        <txp:article_custom sort="UPPER(Title)" 
                            breakform="glossary_sections"
                            breakby="glossary_sublists"> 
          <li><txp:permlink><txp:title /></txp:permlink></li>
        </txp:article_custom>
    </txp:if_category>
</txp:if_article_list>
<txp:article sort="UPPER(Title)" 
             breakby="glossary_sublists" 
             breakform="glossary_sections"  
             listform="terms_alphabetical" 
             form="default"
             class="termslist" />

In that last article tag, I’ve added the same breakby and breakform attributes because it makes the filtered list from the default page consistent in structure/appearance with the full glossary lists; i.e., term titles under their respective lettered headings.

The other two forms are thus:

  • listform="terms_alphabetical is just a wrapping permlink tag on a title tag inside lis.
  • form="default" is my full article view markup
glossary_sections form:
<section>
    <h3><txp:yield item="breakby" /></h3>
    <ol class="termslist"><+></ol>
</section>
glossary_sublists form:
<txp:evaluate query='substring(<txp:title escape="quote" />, 1, 1)' escape="upper" />

All of that is nearly giving me the two conditions below, as desired. I’ve got all boxes ticked (i.e. behaviour is working) except for the one in Condition B.

Condition A:

[x] Category list on homepage
[x] Click category link; taken to Glossary section where a sole list of associated glossary displays
[x] Click title in the filtered article list, full article opens.

Condition B:

[x] Click ‘Glossary’ link in main nav; full glossary list displays (default view) with terms grouped by their alphabetical heading [YES]
[ ] The full glossary with section-headed lists display, as desired? [YES and NO. The full glossary presentation is correct, but the full glossary outputs in duplicate, one after the other. I only want one full glossary]
[x] Click a link in the full glossary list; it opens the the full article by itself? [YES]

I’m guessing the fact that it’s close to working is probably a coincidence and not because it’s close to correct. Probably full of typos, too. There are no tag errors, though, and it’s in debugging mode.

Guidance at this point is welcome, because this new tag logic is indecipherable to me. All I can say is, if I change anything, it breaks either the homepage or the glossary page output in other ways. So I haven’t been able to find the secret sauce, or what is missing and where to get that one box ticked.

Last edited by Destry (2020-09-23 07:30:39)

Offline

#36 2020-09-23 07:28:47

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

Re: Categories list here, related article output over there

[ ] The full glossary with section-headed lists display, as desired? [YES and NO. The full glossary presentation is correct, but the full glossary outputs in duplicate, one after the other. I only want one full glossary]

I think all you need is to take out the article_custom tag that’s showing in the full list view because the txp:article tag (without _custom) at the bottom is already doing that part, i.e.:

<txp:if_article_list>
    <txp:if_category>
        <h1>Glossary</h1>
        <h2>Entries under <txp:category title /></h2>
        <txp:hide>Filtered list of articles magically appear here.</txp:hide>
    <txp:else />
        <h1>Glossary</h1>
    </txp:if_category>
</txp:if_article_list>
<txp:article sort="UPPER(Title)" 
             breakby="glossary_sublists" 
             breakform="glossary_sections"  
             listform="terms_alphabetical" 
             form="default"
             class="termslist" />

And you could shorten that a bit, seeing as you’re making the Glossary h1 appear either way to:

<txp:if_article_list>
    <h1>Glossary</h1>
    <txp:if_category>
        <h2>Entries under <txp:category title /></h2>
    </txp:if_category>
</txp:if_article_list>
<txp:hide>
    in article_list view txp:article lists the articles filtered by category else the full list.
    in individual_article view txp:article shows the full entry.
</txp:hide>
<txp:article sort="UPPER(Title)" 
             breakby="glossary_sublists" 
             breakform="glossary_sections"  
             listform="terms_alphabetical" 
             form="default"
             class="termslist" />

I’m not arguing because I don’t have the specs memorized, but if a list is in alphanumeric order, doesn’t that make it an ordered list?

Sounds like a plausible reason you suggested. It’s up to you :-)


TXP Builders – finely-crafted code, design and txp

Offline

Board footer

Powered by FluxBB