Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


Provide a way to add multiple content handlers #63

naholyr opened this Issue · 8 comments

4 participants


We can have many helpers, hooks, etc… but only one content handler, this makes it quite uneasy to append new content handlers above existing ones. For example in my case I use:

  • my dedicated custom content handler for some specific pages, which falls back to…
  • a content handler generating RSS, itself using…
  • blog-content-handler, which falls back to…
  • default content handler

Maybe the content_handler(s?) option could be an array, and core would:

  • unshift default content handler (so it's always here, cannot be disabled, or another option?)
  • concatenate all their "getSections" & co
  • for every negotiation: call all "negotiateContent", and merge provided contents (in the same order, last handler = most priority)

I don't think this would be too hard to do. What do you think? Do you see major issues with this vision (before I start working on PR)?


I can't comment on the specifics (I just don't have that great an understanding) but I have developed a feeling that Punch's content processing is a bit limited and simplistic. Being able to stack handlers would help. As would being able to run helpers on content before handlers, rather than just in templates.

Most of the issues can be got around by writing custom content handlers but those are harder to re-use on different projects and you can't share with the wider community so easily.


The recommended way to have multiple content handlers is by using the delegation pattern. If you look at the blog-content-handler's code it's implemented this way (by delegating to default content handler when it cannot handle something).

I will write a better tutorial to make this more clear.

@adrinux I'm considering on the idea of making helpers accessible from content handler. Will do some experimentation on that.


Delegation can't be enough, it prevents building efficient third party content handlers. Let's take an example:

  • I've built a content handler generating RSS, working as an overlay to punch-blog-content-handler.
  • I plan building something similar to handle comments (one that will extend content returned by getPosts for example).
  • What if I want to use them both on same time? No way else than editing one of them to delegate to the other instead of delegating to blog-content-handler :( Same applies each time I will want to use two third-party content handlers.

Maybe we could address this issue by providing a helper or snippet to allow configuring delegation (I could say in config.json that I want comments-content-handler to delegate to rss-content-handler instead of directly blog-content-handler, and it would be enough). But in the end, it will the same than providing an ordered list of handlers instead of a single one ;)

Well, actually I'll make my RSS generator a generator_hook, but the need still is here in my opinion. That's why I was wondering if there was a true limit or if there was some space for extra work ;)


I guess what we need here is a routes-content-handler which can sit on the top and do the delegation based on the URL paths.

I'll try to make it to work during the weekend.


Just as another use for the content handler: I'm currently working on a content handler that, given a picasa album name in the original json expands that json by including urls to the images in that album. I can do this with the current delegation, however I don't think a routes-content-handler will help me here. Or should I be doing this in a completely different way?


Content delegation does work, but the routes-content-handler will not. I was hoping to provide some more input here with other use cases. Thanks for the input, though!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.