     after_category: (ctx, category) ->
       return unless category == @category
 
+      @layoutFile ||= layoutFiles[@layoutFilename]
+      throw("No layout #{@layoutFilename} found for #{category}") unless @layoutFile
+
       adapter = @layoutFile.adapters[0]
       content = @layoutFile.originalContent
       opts = @configure_options(@layoutFile, adapter)

    )
  array

module.exports = (options) ->
  options ||= {}
  folder = options.folder || "posts"

      @category = "collection_#{options.folder}"
      @entries = []
      @roots.config.locals[helperName] = decorateArray([])
      @layoutFilename = "views/#{options.layout}.jade"

    frontmatter_regexp: /^---\n([^]*?)\n---\n([^]*)$/
    slug_date_regexp: /^([0-9]{4})-(\d\d?)-(\d\d?)-/

    fs: ->
      extension = @
      extract: true
      ordered: true
      detect: (f) ->
        if f.relative == extension.layoutFilename
          true
        else
          path.dirname(f.relative) == folder
