We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 2327
    • 214 Posts
    Hello,

    Do you know the plugin Autotoc, able to generate a synopsis of document based on the H tags ? Here is the link : (http://modxcms.com/Automatic-TOC-Navbar-994.html).

    This plugin functions perfectly, but unfortunately does not restore the hierarchical level of the H titles in the HTML result. They leave all on the same level without means of differentiating them…

    I think that it would take 2 minutes for an expert php to solve this problem.
    The lines concerned with this problem (generation of the <ul><li>… </li></ul> of the TOC) go from line 125 to 135 in script.

    An idea? Its author is unfortunately not available at this moment.

    Thank you very much if the subject interests you smiley kiss

      • 7231
      • 4,205 Posts
      I have thought about this for another use. The trick is to identify the ’level’ of the item. There are to many alternatives that make this a bigger problem than just a few minutes to resolve (I sure ain’t no doctor, so a real doctor could do better). Here is an example scenario:

      h1
      --h2
      ----h3
      ------h4
      h1
      h1
      ----h3
      --h2
      h1

      We know that you should use a hierarchy but it is not always the case. How would the above case be outputted?
      <ul>
        <li>h1</li>
          <ul>
            <li>h2</li>
              <ul>
                <li>h3
                  <ul>
                    <li>h4</li>
                  </ul>
              </ul>
          </ul>
      <li>h1</li>
      <li>h1</li>
      <ul>
          <ul>
             <li>h3</li>
               <ul>
                 <li>h2</li>
              </ul>
          </ul>
      </ul>
      <li>h1 </li>
      </ul>


      To get this to work each item needs to know if it is a child of another file and ’remember’ the depth and parent/child state. Also what happens if there is a lonely h2. Will it show up as second level or first level. I am interested, but it is a bit beyond my mental capacity to figure this out.
        [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

        Something is happening here, but you don&#39;t know what it is.
        Do you, Mr. Jones? - [bob dylan]
        • 2327
        • 214 Posts
        Thank you very much, dev_cw !

        I believe to understand the problem which you raise… Another solution would perhaps simply consist to assigning a class at the exit code according to the initial level of the title (h1: class= " toto", H2: class= " titi ", ...) ?

        I know it is less clean with dimensions code, but isn’t this more simply realizable ?

          • 10449
          • 956 Posts
          hmm, I think this could be better solved with using XML as input-format. You can nest nodes in XML any way you want (as long as it’s well-formed, of course). But this being a Saturday afternoon, I can think of a few more entertaining activities right now smiley
            • 2327
            • 214 Posts
            Thank you very much.

            In fact, with you and Sottwell, I could solve the problem via the plugin Page TOC generator http://modxcms.com/forums/index.php/topic,20583.0.html

            Version corrected by Sottwell (it seems that there has a problem on the last version in line 203 of Page TOC …).

            Thank you still!