contao/import — Issue #3104: Add AjaxTemplate Class to Frontend Module
Author: importer
Created: 2011-11-29 20:54:00+00:00
State: open
Labels: Feature, frontend

There are times when it is preferable to do an ajax update to a page. For example using an ajax instead of a form post

I add the js to my template to handle this,
Then I add generateAjax() function to my Module, and I would like to use the same template as I already use when ajax is not invoked.

But there's no straightforward way to just use the same template.

Solution create AjaxTemplate class which extends Template but adds nothing to it, see code below:

```
..in Module...
public function generateAjax()
{
$this->Template = new AjaxTemplate($this->strTemplate);
//use standard compile function for ajax requests if you can
$this->compile();
return $this->Template->output();
}

...in Frontend extension add file AjaxTemplate.php ...
class AjaxTemplate extends Template
{

}
```

With the code above I can service ajax requests without repeating code.

--- _Originally created by wal5hy on May 24th, 2011, at 07:21pm (ID 3104)_