I manage a Drupal 7 based website for my College’s Student’s Association. Most of it is standard static pages. Each year we run a room ballot for people to choose their rooms and this process will need an application to display current room allocations (in real time) and wiki style information about what the different rooms are like.
I need to be able to serve up static pages of HTML, javascript and css; bypassing the theming module. I need the relative addressing in the html page which serves as the root of the application to work properly (e.g. “javascript/app.js” should pick up that file from within the module). I then need to serve up json data from php using all the drupal APIs for permissions and database access etc.
I have a fair bit of experience in HTML, Javascript etc. and some in PHP, but I’m fairly new to Drupal module development.
You should create a custom module as you suggest, and separately put your HTML5 application in a sub-folder of the module. When it’s accessed it will use the same relative paths as you’d normally expect so
javascript/app.jswill work if the file exists in the path under your HTML5 app’s folder.For the JSON data your custom module will look something like this:
That code defines a menu path (using
hook_menu()) atmp/app/datawhich usesmymodule_ajax_callback()as it’s page callback.mymodule_ajax_callback()simply grabs all nodes from the database that match thetypeparameter passed in the AJAX$_POSTand outputs their id and title in a JSON string to the page (which will then be returned as your AJAX response when you request/my/app/path).Hope that helps