Thread:Project:Support desk/How to render TOC at a custom place in PHP/reply (3)

I am not sure, if I got you, but the ForceTocOnEveryPage extension is executed in a hook inside the parser object. The extension can add the TOC, because the code, which is generated at that point is parsed afterwards, The sidebar in contrast is not. I guess the same goes for div class=sidetoc: When it is not added from inside the parser object, it - by default - won't be parsed afterwards.

However, it might make sense for you to use this extension anyway: That kind of guarantees that the TOC appears everytime at exactly the same place of the DOM.

Another idea would be: Check Manual:Hooks and see, if there is a hook, which allows modifiying the generated TOC. If so use it and save the source code of the TOC in a global variable. Later, when you are creating your sidebar, take the stuff from the global variable and put it there. However, this is not really clean and it would only work, if the sidebar would be processed after the main content (what would seem logical to me, but what I don't know).

Another idea might be to use jQuery to manipulate the DOM the way you need it.