Monday, April 22, 2013

Table of Contents Styling

Sharepoint is built, like Venice and other cities widely beloved yet reeking with sewage floodwater, mainly on itself and a swamp. It is less a piece of software than an ongoing, hierarchical conversation, maybe conducted with whips. Also like Venice, it periodically wets the broadloom for no apparent reason.

Table of Contents webparts are one of those less-baked parts of Sharepoint.

A TOC is handy. It lets you list subsites and key pages relatively easily, mainly by ticking tickyboxes, which tick nicely. The trouble comes with Sharepoint's file architecture, which is le dodgy below a few levels. Much as how the Quicklaunch/left navigation menu acts plain weird and sometimes disappears for no reason, the TOC is always displaying dynamic content, and will occasionally change how it displays with no warning whatsoever. This is irritating, because TOC pages are almost only ever needed when you are presenting an Important Portal Site that is supposed to fool someone familiar with paper into thinking they are not on the Internet. Sad face. Here is how to fix things randomly disappearing and or changing their style and or publicly breaking.
  • The style sheet called Table of Contents Main contains no styles whatsoever for your table of contents.
  • It styles columns.
  • To style Table of Contents items, you must go to LevelStyle.xsl
  • The margins have all been hard-coded, a level of grief that you are by now as accustomed to as Midwesterners are familiar with drought.
  • If you go into LevelStyle.xsl, you can yank the inline margin-setting shenanigans. Thank Christ. You could also recode them there, probably, use what look like somewhat nifty variables which are totally fuckered by any kind of page layout work.
  • Fuckered is a technical term.
  • If you're creating a table of contents in a subsite that is further than one level from the top of the site (IE: Is already in [server:port]/first-level/second-level/ ), guess what?
    • It will not display the pages as a nicely bulleted list. It simply treats the site itself and all the site's subfolders as an equivalent level.
SharePoint cannot handle anything deeper than a two-level architecture. Maybe three. That's when all its generative menu code breaks, so don't even bother. This means ... yes! XSL haxx. Yes it does. Hack at it. 
  1. Copy the Vertical style template in LevelStyle.xsl
  2. Paste and rename Vertical Bullet. 
    1. This way, your many functional tables of contents will not be damaged.
  3. Set the template name as follows, wiping the match="*" value because that'll bung your other pages.   <xsl:template name="VerticalBullet" match="Level[@LevelTemplate='VerticalBullet']">
  4. Ax the span-tag to which the default styling applies.
  5. Return to your main page.
  6. Set your top level style to Vertical, and your second level to your new VerticalBullet style. The second level will instantly behave because there are no inline tags on the hunt for it any more.
Confirmation of the existence of the problem and source of where the levels styles can be found comes from here:
http://tomblog.insomniacminds.com/2007/10/12/sharepoint-branding-issues-table-of-contents-webpart/

Gist of my own XSL level styles, with CSS on top because you fully know you need to copypasta this into your own bizarre filestructure. Put the CSS in your CSS, put the XSL in wherever you store your XSL level styles. Then get a beer. I hope you have a bullet in your _layouts.

1 comment:

  1. You sir, are full of quality and have me falling out of my chair with guffaws. I feel your pain.

    ReplyDelete