On 8/2/16, António Ramos <
ramst...@gmail.com> wrote:
> any demo with web2py?
I'm using it at
http://missportuguesa.pt in a simple way.
in my first model file:
request.pjax = True if request.env.get('HTTP_X_PJAX') == 'true' else False
In layout.html:
<hrml>
<body>
(...)
<ul class="nav navbar-nav">
<li><a data-pjax href="{{ =URL('index') }}">Home</a></li>
<li><a data-pjax href="{{ =URL('some_page') }}">Some page</a></li>
</ul>
(...)
<div id="pjax-container">
{{ block content }} <div class="container">{{ include }}</div> {{ end }}
</div>
(...)
<script src="{{ =URL('static', 'js/jquery.pjax.js') }}"></script>
$(document).ready(function() {
$(document).pjax('a[data-pjax]', '#pjax-container')
})
<body>
</html>
In default/index.html:
{{ extend 'layout.html' if not request.pjax else None }}
{{ block content }}
{{ # Here in all links I put a data-pjax attribute }}
<a data-pjax href="{{ =URL('index') }}>Home</a>
{{ end }}
Drawbacks I found:
- You should take care when using javascript libraries, since the
pages are not fully loaded in every request, some references:
*
https://github.com/defunkt/jquery-pjax/issues/560
*
http://stackoverflow.com/questions/9696119/where-to-put-the-page-initialize-javascript-when-using-pjax
- Using {{ extend 'layout.html' if not request.pjax else None }} in
views you cannot compile views
Ricardo