# include

## Purpose

Includes the response of another controller/action or view in the current response

## Examples

Example controller for an application called "shop":

    class BookController {
         def list = { [ books: Book.list( params ) ] }
         def show = { [ book : Book.get( params['id'] ) ] }
    }

Example usages for above controller:

    <g:include action="show" id="1" />
    <g:include action="show" id="${currentBook.id}" />
    <g:include controller="book" />
    <g:include controller="book" action="list" />
    <g:include action="list" params="[sort:'title',order:'asc',author:currentBook.author]" />

Example as a method call in controllers, tag libraries or GSP:

    def content = g.include(action:'list',controller:'book')

## Description

Attributes

- `action` (optional) - the name of the action to use in the include
- `controller` (optional) - the name of the controller to use in the include
- `id` (optional) - the id to use in the include
- `view` (optional) - The name of the view to use in the include
- `params` (optional) - a map containing request parameters
- `model` (optional) - Any request attributes (the model) to pass to the view to be included

## Source

Show Source

    def include =  { attrs, body ->
    		if(attrs.controller || attrs.view){
    			def mapping = new ForwardUrlMappingInfo(controller:attrs.controller,
    													action:attrs.action,
    													view:attrs.view,
    													id:attrs.id,
                                                        params:attrs.params)			out << WebUtils.includeForUrlMappingInfo(request,response,mapping, attrs.model ?: [:] )?.content
    		}
    	}