Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#13 2020-12-23 20:13:58

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

Re: soo_toc table of contents generator

Hi Jeff! Nice to see you around. I’ve been using the plugin so long a certain way, I guess I started assuming that was the only way. Never mind me. Everything I need is there. /goes back to dunce corner /

Offline

#14 2020-12-23 20:36:03

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,793
Website

Re: soo_toc table of contents generator

Well, I’ll join you there. What I said above about the limit attribute isn’t quite correct; it will match the actual h-tag number. I’ve corrected my example in my last post above.


Code is topiary

Offline

#15 2020-12-25 14:23:51

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

Re: soo_toc table of contents generator

Merry xmas, everyone. I’m sitting around at the in-laws doing squat so, you know, ironing out web problems.

This is to anyone, but I suspect it’s a situation with how the plugin works. Not being a dev, I can’t say. This is only local dev for the time being, but…

I’ve managed to refactor my CSS so that soo_toc now powers both the ordered and unordered contents lists; e.g. my policies page using <txp:soo_toc wraptag="ol" />, and any ‘default style’ contents lists elsewhere using the plugin’s default ul (no wraptag needing declared).

My contents lists are all marked up consistently within a section element like this:

<section id="contents">
  <hr class="startrule">
  <h2>Contents</h2>
  <txp:soo_toc  />
  <hr class="endrule">
</section>

That works and looks as designed when the markup is added to the top of the body field.

Naturally, I want to minimize that eyesore by using an easier to remember shortcode instead (called contents). The one I showed before without the wraptag="" attribute incorporated works fine, rendering output as expected.

But as I just discovered, if I add the wraptag attribute to the shortcode to account for all list type situations in my newly refactored CSS:

<section id="contents">
  <hr class="startrule">
  <h2<txp:if_article_id id="3"> class="nosync"</txp:if_article_id>>Contents</h2>

  <txp:soo_toc level='<txp:if_yield name="levels"><txp:yield name="levels" /></txp:if_yield>' 
               wraptag='<txp:if_yield name="wrap"><txp:yield name="wrap" /></txp:if_yield>' />

  <hr class="endrule">
</section>

…the shortcode won’t work.

That is, if I declare ol (<txp::contents wraptag="ol" levels="4" />), the ol elements wraps the entire section block:

<ol>
<section id="contents">
  <hr class="startrule">
  <h2>Contents</h2>
  <li><a href="#idselector">Heading</a></li>
  <li><a href="#contents">Contents Items</a></li>
  <li><a href="#contents-l1">Test h3</a></li>
  <li><a href="#contents-l2-1">Test h4</a></li>
  <li><a href="#contents-l2-2">Test h4</a></li>
  <li><a href="#table">Table Tester</a></li>
  <li><a href="#form">Form Tester</a></li>
  <hr class="endrule">
</section>
</ol>

If I leave out that attribute to use a default ul list (<txp::contents levels="3" />), no ul elements is added at all:

<section id="contents">
  <hr class="startrule">
  <h2>Contents</h2>
  <li><a href="#idselector">Heading</a></li>
  <li><a href="#contents">Contents Items</a></li>
  <li><a href="#contents-l1">Test h3</a></li>
  <li><a href="#contents-l2-1">Test h4</a></li>
  <li><a href="#contents-l2-2">Test h4</a></li>
  <li><a href="#table">Table Tester</a></li>
  <li><a href="#form">Form Tester</a></li>
  <hr class="endrule">
</section>

How to fix?

Last edited by Destry (2020-12-25 14:31:27)

Offline

#16 2020-12-25 16:07:28

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

Re: soo_toc table of contents generator

Hi Destry,
Did you try using the labeltag and label attributes? I also sightly amended your yields.

<section id="contents">
  <hr class="startrule">
  <txp:soo_toc <txp:if_yield name="levels">level='<txp:yield name="levels" />'</txp:if_yield> 
               <txp:if_yield name="wrap">wraptag='<txp:yield name="wrap" />'</txp:if_yield>
               label="Contents"
               labeltag="h2"
 />
  <hr class="endrule">
</section>

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

Offline

#17 2020-12-25 16:27:36

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

Re: soo_toc table of contents generator

Slightly confused. Your short code yield is looking for the wrap attribute but you’re passing in wraptag. Might this work better? …

<txp::contents wrap="ol" levels="4" />

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

#18 2020-12-25 16:35:09

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

Re: soo_toc table of contents generator

Bloke wrote #327854:

Slightly confused. Your short code yield is looking for the wrap attribute but you’re passing in wraptag. Might this work better? …

I took it that Destry used a shorthand for wraptag in his yield name.


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

Offline

#19 2020-12-25 16:37:04

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,793
Website

Re: soo_toc table of contents generator

I’ll have to think about this one a bit. Currently, if soo_toc has a wraptag other than ul (the default) or ol, it returns a simple (i.e., non-nested) listing of all h# elements, using the wraptag and break as usual for Txp. So that’s what’s happening here.

So maybe a quick-and-dirty solution would be something like this:

<section id="contents">
  <hr class="startrule">
  <h2<txp:if_article_id id="3"> class="nosync"</txp:if_article_id>>Contents</h2>

  <txp:if_yield name="wrap"><txp:yield name="wrap" />
    <txp:soo_toc level='<txp:if_yield name="levels"><txp:yield name="levels" /></txp:if_yield>' wraptag="ol" />
  <txp:else />
    <txp:soo_toc level='<txp:if_yield name="levels"><txp:yield name="levels" /></txp:if_yield>' />
  </txp:if_yield>

  <hr class="endrule">
</section>

assuming that ol is always the wraptag you want in this case. Not pretty, but perhaps it will work?


Code is topiary

Offline

#20 2020-12-25 17:09:32

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

Re: soo_toc table of contents generator

A lot of people at the in-laws, apparently. ;)

colak wrote #327855:

I took it that Destry used a shorthand for wraptag in his yield name.

Correct. I was just naming the yield tag, but using the plugin’s wraptag attribute and passing in a value of ol.

But, Colak’s code works!

I don’t know why, but using the plugin’s label and labeltag attributes instead of straight markup made the problem go away.

(I also changed the h2 to h1 to be consistent with similar section headers (back matter sections), and that allowed me to remove three ugly CSS lines. But that’s a different thing.)

Thanks, gents. Back to your nog.

Last edited by Destry (2020-12-25 17:15:23)

Offline

#21 2020-12-25 17:21:03

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

Re: soo_toc table of contents generator

Bloke wrote #327854:

Might this work better? … <txp::contents wrap="ol" levels="4" />...

Actually, you might be right. I thought I knew what I was doing, but it was still throwing a wrench. I just made it all consistent wraptag now through the naming and it seems okay.

Offline

Board footer

Powered by FluxBB