Chapter 10.3: Doing AJAX with Curry
In this chapter we will discuss AJAX handling with Curry CMS. Curry does not have any special AJAX wrapper or support. You will have to do AJAX the regular way with JavaScript. Curry does have features that allow you to work with "portions" of a web page. You can inform Curry to render a certain module attached with a web page.
curry_show_page_module_id
and curry_ajax_page_module_id
parameters
The curry_show_page_module_id
query parameter informs Curry to return the parsed template of the specified module. The "page module" id is specified in the value part of the query parameter. When Curry CMS reads this parameter it will render only the specified module irrespective of whether the request is made with JavaScript.
For example, modify the cms/templates/Modules/CompanyList.twig
template as follows:
<ul data-module-id="{{ module.Id }}">
// Code removed to focus on relevant portions
{{ module.Id }} will print the page module id when the template is rendered. Now access the front end from the URL path
demo/companies/. On Chrome, open the web inspector tool and see what is the page module id. Now add the
curry_show_page_module_idparamter to the URL; e.g.
demo/companies/?curry_show_page_module_id=8`. When the page is rendered you should see only the company listing.
The curry_ajax_page_module_id
behaves a little differently. When the request is an AJAX request, Curry will return the specified module's output else the whole page will be rendered.