Table of Contents Pro

ExpressionEngine 2

Back to this add-on's main page
View Other Add-ons From Mark J. Reeves


You must be logged in to post.

TOC conditional display on page

Support Request


Hi, your plugin is very good. Works fast. But I would like to show the (for example) “Page Contents:” headline before the TOC links list just only on pages containing TOC links not on other ones using the same template. When I include headline after {exp:toc} - it’s not shown on links list. Do you have any suggestions how to properly do that?


Mark J. Reeves
# 1
Mark J. Reeves

Hi Greg,

I understand what you’re describing. That wouldn’t be possible as this is built, as everything between the start & end tags is parsed to find headings to generate links with. So if you add a heading inside there, it’s just seen as part of the content that’s parsed. (With that in mind, as long as it’s valid XHTML, you should be able to put multiple fields or strings of text between the tags.)

I do have two possible solutions for you, though:

1. I’ll put it on my to do list to support something like exp:toc:count in ToC Pro. I think this would be useful, and would enable you to have a conditional *before* your {exp:toc} tag, such as:

{if exp:toc:count 0}<h2>Page Contents:</h2>{/if} 

2. In the meantime, you should be able to accomplish the same thing this way:

{if "{wysiwyg_field}" != ''}<h2>Page Contents:</h2>{/if}

Since ToC is only going to generate its <ul> of links if that field has content, you can check that field to determine whether you’ll show your field. There is a hole in this approach: If the field has content but does not have any headings, the headline would still output.


Mark J. Reeves
# 2
Mark J. Reeves

Playing around with this a bit, and I think it’s going to entail reworking the whole plugin. It will result in two things:

1. The plugin won’t be able to automatically output the <ul> of contents/links. It will need a tag within its start/end tags to output that. A tag variable.
2. With that in place, I can provide a {count} variable as well.

How then to pass in the content to parse? This is the thing I need to figure out. The contents of the tag can’t be the contents to parse once the tag contains tag variables. So it might need to be params (channel=”” entry_id=”” field_name=”“}.

Not ruling it out, but it’s something I’ll need to think about more.