I tried to put this code in layout.html so that I do not need to put it in every view.It works when there is grid on page but throws an error when there is no grid. Seems logical ;) but I dont know how to check in layout.html if grid exist.