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

Your snippet will just return the HTML comment. In order to get the expected result you would have to have a parser object through which you can send your comment so that the parser replaces it with the actual TOC. However, even if you called a parser object I am not sure if it contains the article at the point in rendering when your sidebar is being created = when you would need it. Without testing, I guess that you would have to parse the whole article a second time.

You won't be able to do something like that inside a hook I think. So any stuff in PHP will become rather expensive as you will basically have to render the article twice: Once to get the article and once to get the TOC. I wouldn't want that.

Have you tried to achieve that with CSS?