Q:

Symfony2: custom response according to request

I have action which I want to return different response, depending on which page this action was called.
This is an action
 /**
 * @Route("/collection_create_submit", name="collection_create_submit")
 */
public function createSubmitAction(Request $request)
{
    $collection = new Collection();

    /* other code*/

    if (???){
    return $this->render('@Collection/Collection/createSubmit.html.twig', 
                          array('collection' => $collection));
    }else{
    return array('collection' => $collection);
         }
    }
}

So, for example, if action was called on list.html.twig, I want to render createSubmit.html.twig template. If it was called on show.html.twig, I only want to get Collection object.

A:

As already mentioned in the comments you can easily use a parameter for this.
public function createSubmitAction(Request $request, $render = false)
{
    $collection = new Collection();

    /* other code*/

    if ($render !== false){
        return $this->render('@Collection/Collection/createSubmit.html.twig', 
                          array('collection' => $collection));
    }
    else{
        return array('collection' => $collection);
    }
}

