Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

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

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,388
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: 12,476
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.

Hire 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,388
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,912
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,912
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