[owncloud-devel] DOM messed up after loading new, #app-content as TemplateResponse via Ajax

Bernhard Posselt dev at bernhard-posselt.com
Sat Apr 11 11:13:17 GMT 2015

It fully depends on what you want to do. If you want to make a full page
reload you do not want to  use a blank template. If you however just
want to replace content in the content area, you want to have a blank
template response for the loaded html (not the initial page load).
Because this is just a partial template, there is no head tag and
therefore no script tag, so loading scripts in blank template responses
wont work.

I suppose you want to have a full ownCloud page when a user loads the
app, and when he clicks something in the navigation, you want to load
html into the content area. In that case you return a normal
TemplateResponse for the index page. Via JavaScript you then load blank
template responses via ajax and put them into the content are. In that
case your JS is already loaded by the initial page.

As for the 404 response:

$response = new \OCP\AppFramework\Http\Response();
return $response;

If you find that you are using this very often and dont want to return
content, you can ofc create your own response class (see

class NotFoundResponse extends \OCP\AppFramework\Http\Response {
    public function __construct() {

then you can do:

return new NotFoundResponse();

PS: there might be typos in my code ;)

On 04/11/2015 12:40 PM, Marcus Mundt wrote:
> "You have to pass in the renderAs parameter which needs to be blank"
> I was already looking into the parameters of TemplateResponse. Thanks
> for making that clear to me!
> Did so, but now none of the JS files the templates depend on are
> loaded, therefore no function at all, but the pure HTML is replaced
> correctly.
> Also changed as much as I could based on your hints. But some of the
> "fancy" stuff like client-side templates will be postponed, since I
> need to get my app up and running.
> Is it correct to use something like:
>     $notFound = new NotFoundResponse();
>     $notFound.setStatus(404);
>     return $notFound;
> instead of:
>     header("HTTP/1.0 404 Not Found");
> And regarding "* You should get rid of private apis like OC_Log"
> I'll have to read up on this, no clue for now
> Thanks a lot Bernhard!
> _______________________________________________
> Devel mailing list
> Devel at owncloud.org
> http://mailman.owncloud.org/mailman/listinfo/devel

More information about the Devel mailing list