AJAX, organization of extra content and CMSMS

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
nhaack

AJAX, organization of extra content and CMSMS

Post by nhaack »

Hi there,
1) AJAX
I sometimes make use of AJAX to add some spice to the sites I build and to make plug-ins like the API collection less time consuming by initially loading smaller chunks and then let users explore content "onDemand".

I use a few Javascript functions that you can find attached in the file "ajax.txt" (rename to .js). It uses two XHTML elements (I use DIVs) and basically swaps their visibility mode (to display a loading box) while replacing the actual content.

The content I want to load is stored in an extra page (template empty, except for logic and content) that I store in an extra content tree folder which is hidden from the navigation (more about that later).

To make the AJAX call to the other page to fetch some new content, you just need to state your desired page and the two DIVs used for the action. E.g. the following will hide the div "show_content", display div "waiting_message", replace div "show_content" with targets data and swap display again when completed (with pretty urls having no file extension)

Code: Select all


<div id="show_content">replace me!</div>
<div id="waiting_message">// fetching new stuff //</div>

<a href="javascript:makeRequest('ajax-content','waiting_message','show_content')">do it</a> 

This can be combined with passing data via the URL using GET parameters, with little adjustment of the script, it is also possible to use POST to build really interactive stuff.

It really works like a charm. It works so nicely, that not being a programmer, I wonder if it can be too good to be true (have I said that I always avoided javascript since I hated it and now suck at it and think it's cool?).

Apart from being a technique that is wired directly into the template, which is not module/plug-in based, what do you think of the general approach? Do you use AJAX in your sites?


2) Content Organisation

The content that is fetched, as mentioned, is coming from regular content-pages that are based on an empty template but have a second content block that is explicitly set to wysiwyg = false. Each of the pages then contains some logic and content according to its purpose. This could be some random image/quote/comment or an interactive use of other sites APIs, or just static text... whatever ;)

A content tree could look like that:

1 - Home
2 - Products
2.1 - Our Youtube Videos (accessing 4.1.1)
3 - About us
4 - Tools (structure, all is hidden)
4.1 - AJAX Handler (structure)
4.1.1 - Youtube Search API (special template)

It is a little inspired by the DAY CQ CMS, where everything is more or less node-based in a single content-bus and a lot of site settings & content is organized in a single tree. I find myself using this technique more and more as it also seems to work nicely in CMSMS and I feel comfortable with it (and editors liked it as well). Of course, for specific needs I use modules/plug-ins and their respective admin areas.

How do you organize extra functionality and settings in your installations? Would you always go for an extra module? Is this what CMSMS is all about (giving you more flexibility than you can sometimes handle)? :)

I am curious for your answers.

Best
Nils
Attachments

[The extension txt has been deactivated and can no longer be displayed.]

Post Reply

Return to “Developers Discussion”