javascript - Render cherrypy's template with id/hash -
how render page , go specific id?
right have following function code:
@cherrypy.expose @require def page(): tmpl = lookup.get_template('page.html') return tmpl.render()
however, page.html
have several subpages, can access through url mydomain.com/page#someid
.
is there way render template go directly id?
i think mixing ideas, #
part of url client duty focus in specific element id. nevertheless, suppose want dynamically embed chunks of particular part of page trough javascript, can think on 2 possibilities:
one, compose full page template different ids different sub-templates, easy if using template module, mako, , make cherrypy handler return indivudual parts, of course supposing in control of content of page , ids not dynamic (generated db or something) , main site bunch of includes
.
@cherrypy.expose def page_part(section): tpl_name = 'page_%s.html' % section # validate template exists, then: tmpl = lookup.get_template(tpl_name) return tmpl.render()
mako templates:
page.html:
<html> <body> <div id="main"> main content of site! </div> <h4>sections</h4> <div id="section_1"> <%include file="page_section1.html" /> </div> <div id="section_2"> <%include file="page_section2.html" /> </div> </body> </html>
page_section1.html:
<p> content of section 1</p>
page_section2.html:
<p> content of section 2</p>
or two, use jquery selectors or similar request page once , make sub-selects in returned html.
$.get('/page.html', function(data){ $('#this_page_id').html($('#sect_in_other_page', $(data)).html()); });
Comments
Post a Comment