Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#11 2020-09-27 09:57:36

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

Re: Hidden Section for PP and Terms of Service in Footer

etc wrote #326092:

Extracting a TOC from <txp:body /> (or whatever HTML block) is fairly easy…

Just to be clear, are you proposing this in context of pageless sections, where many articles are being collated, as I was talking about above? If so, I’m not getting it to work. (Though I don’t think I need to use it anyway as I have it working without the plugin.)

Or just as an alternative to soo_toc under normal section/publishing conditions? In this sense it would be good to know. In this context, if I understand right, the query would go in the article form defining the full article output? Something like this?

<article>
<h1><txp:title /></h1>
. . .
<txp:if_excerpt>
  <p class=""><txp:excerpt /></p>
</txp:if_excerpt>

<txp:if_article_image>
  . . .
</txp:if_article_image>

<txp:etc_query data='<txp:body />' query="//h2|//h3|//h4|//h5">
    <{#}><a href="#{@id?}">{?}</a></{#}>
</txp:etc_query>

<txp:body />
</article>

Or does it have to go in its own form, then the form is called with output_form tag in the top of an article’s body field?

Last edited by Destry (2020-09-27 10:00:09)

Offline

#12 2020-09-27 10:12:56

etc
Developer
Registered: 2010-11-11
Posts: 3,940
Website

Re: Hidden Section for PP and Terms of Service in Footer

Destry wrote #326122:

Just to be clear, are you proposing this in context of pageless sections, where many articles are being collated, as I was talking about above? If so, I’m not getting it to work.

You need to collate the articles first, then pass the collated block (stored in some <txp:variable />) to etc_query instead of <txp:body />:

<article>
<txp:variable name="body">
...aggregated articles...
</txp:variable>

...images and so on...

<txp:etc_query data='<txp:variable name="body" />' query="//h2|//h3|//h4|//h5">
    <{#}><a href="#{@id?}">{?}</a></{#}>
</txp:etc_query>

<txp:variable name="body" />
</article>

Yes, it goes into the article form, though you can split it in many output_forms if needed.

Offline

#13 2020-09-27 10:32:51

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

Re: Hidden Section for PP and Terms of Service in Footer

Destry wrote #326091:

One thing I’m wondering…

Another minor hurdle is if wanting to link from one pageless section article to another, the equivalent of an in-page link. You just have to use the id selector as a target: <h2 id="id<txp:article_id />".

So if a ‘Methodology’ pageless-section article ID equaled 37, and one wanted to link from the text of that article to a ‘Conclusion’ article collated later having ID 39, the in-page link would be a relative "conclusion":#id39. Nothing new there.

But one has to know/remember what the respective destination component article IDs are, which are not immediately obvious in context of the Write panel, and if they don’t remember, it’s a jump to the Articles panel to recall. But, still doable.

Offline

#14 2020-09-27 10:44:05

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

Re: Hidden Section for PP and Terms of Service in Footer

etc wrote #326124:

You need to collate the articles first, then pass the collated block (stored in some <txp:variable />) to etc_query instead of <txp:body />

Ah. Variables. Again. Quite a missing detail for this simplton. Thank you. ;)

Offline

#15 2020-09-27 14:51:50

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

Re: Hidden Section for PP and Terms of Service in Footer

etc wrote #326124:

You need to collate the articles first…

It works. Pretty neat. I’m using this:

<txp:etc_query data='<txp:variable name="body" />' 
               query="//h2|//h3|//h4|//h5" 
               wraptag="ul" 
               break="li">
    <{#}><a href="#{@id?}">{?}</a></{#}>
</txp:etc_query>

But how can I change it so it doesn’t output the heading tags like this:
<li><h2>link</h2></li>?

I would prefer just <li>link</li>.

I tried looking at the plugin help, but it’s all a bit over me.

I don’t have any h3 headings, so no nested lists are needed in my case. But I can imagine other situations maybe having those, or lower levels, in which case someone might want nested list output. I think that’s how soo.toc works; changes heading elements to list items and nests them in the contents according to section levels.

Last edited by Destry (2020-09-27 14:57:09)

Offline

#16 2020-09-27 15:55:19

etc
Developer
Registered: 2010-11-11
Posts: 3,940
Website

Re: Hidden Section for PP and Terms of Service in Footer

Destry wrote #326128:

It works. Pretty neat.

Ah, that’s great!

But how can I change it so it doesn’t output the heading tags like this:
<li><h2>link</h2></li>?

I would prefer just <li>link</li>.

Unwrap the links from <#>...</#> which represent the matched tags name (h2 etc).

I don’t have any h3 headings, so no nested lists are needed in my case. But I can imagine other situations maybe having those, or lower levels, in which case someone might want nested list output. I think that’s how soo.toc works; changes heading elements to list items and nests them in the contents according to section levels.

Yes, soo_toc certainly has more TOC-related features than a general-purpose plugin. Probably one can do it with etc_query, but this would need some more involved XPath. But you also could just style headings differently, depending on their levels, to mimic nested lists.

Offline

Board footer

Powered by FluxBB