 			return next(err)  if err
 
 			# Add anything that references other documents (e.g. partials, listing, etc)
-			allStandalone = (false not in standalone.pluck('standalone'))
+			# This could eventually be way better
+			allStandalone = (false not in opts.collection.pluck('standalone'))
 			if allStandalone is false
 				opts.collection.add(database.findAll(referencesOthers: true).models)
 
-			# For anything that gets added, if it is a layout, then add that layouts children too
-			opts.collection.forEach (fileToRender) ->
-				if fileToRender.get('isLayout')
-					opts.collection.add(database.findAll(layoutId: fileToRender.id).models)
+			# Deeply/recursively add the layout children
+			addLayoutChildren = (collection) ->
+				collection.forEach (fileToRender) ->
+					if fileToRender.get('isLayout')
+						layoutChildren = database.findAll(layoutId: fileToRender.id)
+						addLayoutChildren(layoutChildren)
+						opts.collection.add(layoutChildren.models)
+			addLayoutChildren(opts.collection)
 
 			# Forward
 			return next()

		docpad.databaseCache = null

		# Fire plugins
		docpad.emitSerial 'generateAfter', server:docpad.getServer(), (err) ->
			return next(err)  if err

			# Log generated


					# Create file
					file = createFunction(data, options)
					files.add(file)

					# Next
					nextFile()
