# Ajax Request erkennen und anderes Template zuweisen

**URL:** <https://forum.shopware.com/t/ajax-request-erkennen-und-anderes-template-zuweisen/37509>\
**Category:** Programmierung\
**Created:** [16. Juni 2016 um 13:57 UTC](https://forum.shopware.com/t/ajax-request-erkennen-und-anderes-template-zuweisen/37509 "2016-06-16T13:57:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ellwe](https://avatars.discourse-cdn.com/v4/letter/e/e36b37/32.png) [@ellwe](https://forum.shopware.com/u/ellwe)\
**Post date:** [16. Juni 2016 um 13:57 UTC](https://forum.shopware.com/t/ajax-request-erkennen-und-anderes-template-zuweisen/37509/1 "2016-06-16T13:57:40Z")

</div>

Hallo.

Ich arbeite mich gerade in die Shopware und stehe manchmal etwas auf dem Schlauch.

Ich möchte mit einem Plugin ermöglichen, dass der Content eines Herstellers **auch** per Ajax geladen werden kann. Dann aber ohne Header und Footer.

Daraus ergeben sich mehrere Fragen.

1. Wie kann ich in meinem Event einen Ajax Request erkennen?

2. Wie weise ich der bestehenden Action “manufacturerAction” aus dem Controller “Listing” ein neues Template zu? Oder übergebe ich am besten eine Variable $isAjax an das bestehede Template und checke dort per {if $isAjax} den Request?

3. Kann es sein, dass ich die einen CSRF Token mitsenden muss?

Bisher sieht die Bootsrap so aus:

&nbsp;

\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_

\<?php   
 class Shopware\_Plugins\_Frontend\_DMOManufacturers\_Bootstrap &nbsp;&nbsp;&nbsp; extends Shopware\_Components\_Plugin\_Bootstrap &nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; public function getLabel() &nbsp;&nbsp;&nbsp; { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return 'Listing Manufacturers'; &nbsp;&nbsp;&nbsp; } &nbsp;&nbsp;&nbsp; public function install() &nbsp;&nbsp;&nbsp; { &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $this-\\>subscribeEvent( &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'Enlight\_Controller\_Action\_PostDispatchSecure\_Frontend', &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'onListingManufacturer' &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; ); &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; return true; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; } &nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; public function onListingManufacturer(Enlight\_Event\_EventArgs $args) &nbsp;&nbsp;&nbsp; { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $controller = $args-\\>get('subject'); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $view = $controller-\\>View(); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $view-\\>addTemplateDir( &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \_\_DIR\_\_ . '/Views' &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ); &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;$actionName = $args-\\>getSubject()-\\>Request()-\\>getActionName(); &nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if($actionName == 'manufacturer') { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //Hier das Template zuweisen??? &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $isAjax = "Wie kann ich das checken?" &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;$view-\\>assign('isAjax',$isAjax); &nbsp;&nbsp; &nbsp;} &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } } &nbsp; \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_ (Als Codeschnipsel wird es nicht richtig dargestellt) &nbsp; Gruß ellwe

---

<div class="post-metadata">

**Author:** ![ellwe](https://avatars.discourse-cdn.com/v4/letter/e/e36b37/32.png) [@ellwe](https://forum.shopware.com/u/ellwe)\
**Post date:** [16. Juni 2016 um 17:09 UTC](https://forum.shopware.com/t/ajax-request-erkennen-und-anderes-template-zuweisen/37509/2 "2016-06-16T17:09:17Z")

</div>

Gelöst:

&nbsp;

```
    public function install()
    {
	   	 
	     $this->subscribeEvent(
	        'Enlight_Controller_Action_Frontend_Listing_manufacturer',
	        'onListingManufacturer'
	    );

	    return true;
	    
    }
    
    public function onListingManufacturer(Enlight_Event_EventArgs $args)
    {

		if(
			$args->getSubject()->Request()->getActionName() == 'manufacturer' &&
			$args->getSubject()->Request()->isXmlHttpRequest()
			) 
			{
			 $controller = $args->get('subject');
			 $view = $controller->View();	
				
			$view->addTemplateDir(
            	            $this->Path() . 'Views/'
			);
			
			$view->loadTemplate('frontend/listing/ajax_manufacturer.tpl');
		}

      }

```

&nbsp;
