Untitled Document
 
birkit.com: Website Craftsmanship

Creating a TOC from headings

Generating links for a table of contents it is relatively straight forward: select the "header" and "uid" fields from the "tt_content" table and create links to each heading using Typoscript .  In this example we cannot simply do this because the page uses the plugin cc_cbrowse to "split" the content records into multiple pages.

Since cc_cbrowse uses it's own internal pointer to determine the next page is necessary to determine how many browse links cc_cbrowse will create and only link to headings were a split occurs.

This article details how to configure TYPO3 to create a TOC from headers on a page where content has been split into multiple pages with the plugin cc_cbrowse.

Splitting the Page

The headers are generated by simply looking if the value in tx_cccbrowse_browse is greater than 0. 

Although it should be possible to determine from the value if the split occurs before or after in the record, it is easier to just check if a value exists. Therefore, when using the example typoscript to generate a TOC, the records split by cc_cbrowse must be set to "before" (see Fig. 1) rather than "after".

It is also important to set the first record on the page to be split before as well. Otherwise the first record will not show in the TOC.

The example Typoscript also does not really care about the "split" tag used by cc_cbrowse. It will create a link item in the TOC but, since the script does not take into account the kind of split,  the resulting link to the nearest header could be unpredictable.

Typoscript Example:

ARTICLE_TOC = CONTENT
ARTICLE_TOC {
   table = tt_content
   #
   # select the records in the proper order
   # but only where the page has been "split"
   # by cc_cbrowse.
   #   
   select{
      orderBy=sorting
      andWhere=tx_cccbrowse_browse>0
   }
   renderObj = COA
   renderObj {
      #
      # This creates the links as typolinks so that
      # they are compatable with RealURL.
      #       
      20 = TEXT
      20{
         # Value of fgield becomes the link text
         field = header
         crop = 20 | ... | 1
         typolink {
            parameter.data = TSFE:id
            additionalParams.dataWrap = |&tx_cccbrowse_pi1[pointer]={register:myCounter}
            useCacheHash = 1
            wrap = |<br />
         }
      }
      #
      # Here we increment our register var "myCounter"
      # This is done after so that the first link     
      # generated will no value for the &tx_cccbrowse_pi1[pointer].
      #       
      30 = LOAD_REGISTER
      30.myCounter.cObject = TEXT
      30.myCounter.cObject.data = register:myCounter
      30.myCounter.prioriCalc = intval
      30.myCounter.cObject.wrap = |+1
   }
}
#
# Wrap the TOC with a header only if there is a TOC!
#
temp.TOC< ARTICLE_TOC
temp.TOC.stdWrap {
   wrap = <h4>Contents:</h4>
   required = 1
}
page.2.marks.TOC<temp.TOC

Adding an entry to the guestbook