AJAX, Pagination, and Templates

Permalink
Greetings all,

Perhaps I'm overlooking something obvious, but I've encountered an issue that is turning out to be more of a challenge than I anticipated. Basically, the situation is as follows...

I have a block that displays a list. The list will be retrieved via AJAX and will support pagination. I've done AJAX in C5 before via the "tools" mechanism, so no problem there; and pagination seems fairly straightforward. My main concern at this point is that I also want the block to be customizable via the standard C5 template system. The problem is that C5 allows views to be customized, but if the content of the view (i.e.the mark-up) is updated via AJAX, then the file retrieved via AJAX is the one that would have to be changed in order to alter the view; and that's not directly supported by the C5 UI.

It was not immediately apparent to me how to work around this issue and maintain the separation of data from presentation. The only thing that comes to mind is to retrieve the data in JSON format and implement some kind of client-side template approach where the retrieved JSON data are "mapped" somehow to the corresponding DOM elements.

I just wanted to know if anyone else has done this and how you tackled the issue. I will be glad to share my approach if it works out. I'm just wondering if I'm missing another [perhaps better] solution.

Anyway, thanks for any hints or insight you can provide,

-Steve

Shotster
 
Shotster replied on at Permalink Reply
Shotster
Nobody else has encountered this?

Wow, I'm a pioneer, a trailblazer, an explorer going where no developer has gone before. Time to check the dilithium crystals and fire up the warp drive.

Engage...

-Steve
jordanlev replied on at Permalink Reply
jordanlev
Do you mean you want the content manager to be able to add blocks to the part of the page that's updated via ajax? Or you just want to be able to use template files (like page type templates)?

I haven't tried the former (it sounds really difficult). For the latter, though, I just use elements, which can be easily overridden. Just have the tools file call Loader::Element().

Or am I misunderstanding the situation?
Shotster replied on at Permalink Reply
Shotster
Thanks for the reply, Jordan!

> Do you mean you want the content manager to be
> able to add blocks to the part of the page that's
> updated via ajax?

I must confess, I'm not really sure what the "content manager" is. I guess I haven't dealt with that part of the API yet. :-/


> Or you just want to be able to
> use template files (like page type templates)?

What I want is for the user to be able to customize the block via C5's standard template mechanism - i.e. by clicking the block region when the page is in edit mode and choosing "Custom Template."


> For the latter, though, I just use
> elements, which can be easily overridden. Just
> have the tools file call Loader::Element().
>
> Or am I misunderstanding the situation?

I want the user to be able to choose the template from the UI. In other words, a non-technical user must be able to specify a template to use for the block based upon that block's context within the page. The only thing that comes to mind is a client-side template of sorts. I've actually got something working, but perhaps I'm overlooking a more straightforward approach?


Thanks much,

-Steve
jordanlev replied on at Permalink Reply
jordanlev
By "content manager" I meant the user (the person who is managing content on the site, as opposed to the developer and the end-users who are just visiting the site).

So... you want the person who is editing the site to be able to choose a custom template for a block whose content is loaded via ajax.... can't you just have some different custom templates that each call a different tools URL? (Or the same tools url with different GET or POST params?)

If this isn't appropriate, can you provide some more details about exactly how this should work, or better yet post the code of the block in progress (or if this is to go up on the marketplace feel free to pm/email me directly with it if you want me to take a look).

-Jordan
Shotster replied on at Permalink Reply
Shotster
> By "content manager" I meant the user (the person
> who is managing content on the site, as opposed to
> the developer and the end-users who are just
> visiting the site).

Gothca! Haa! I'm so accustomed to API subsystems being referred to as "managers" (window manager, sound manager, etc.), that I forgot about the humanoid types. :-/


> So... you want the person who is editing the site
> to be able to choose a custom template for a block
> whose content is loaded via ajax....

PRECISELY! :-)


> can't you
> just have some different custom templates that
> each call a different tools URL? (Or the same
> tools url with different GET or POST params?)

Yes, but then users who ARE more technically savvy and wish to create their own custom templates can't override the built-in ones in the usual C5 way. In other words, with the approach you describe, they'd have to either create two kinds of files (both a view template AND a tools file), OR they'd have to create just a tools file and follow some block-specific conventions and guidelines established by the block developer.

I really don't want to sacrifice any flexibility OR deviate from the established C5 "protocol" for creating/using custom templates (in terms of the files used/overridden/edited).

With the approach I've developed, the user can follow the already-established and well-documented approach for overriding views and creating custom templates. The only difference is that there's no PHP to mess with; and as such, I actually find it easier to customize.


> If this isn't appropriate, can you provide some
> more details about exactly how this should work,
> or better yet post the code of the block in
> progress (or if this is to go up on the
> marketplace feel free to pm/email me directly with
> it if you want me to take a look).

It is for the marketplace, but once I have things polished and tested, I'll share the technique with the community so others can improve upon it (or point out what an idiot I am). But in short, it's pretty much what I described at the beginning of this thread.

-Steve
Shotster replied on at Permalink Reply
Shotster
> The only thing that comes to mind is to retrieve the data in JSON format and
> implement some kind of client-side template approach where the retrieved
> JSON data are "mapped" somehow to the corresponding DOM elements.

And that's precisely what I wound up doing...

http://www.concrete5.org/community/forums/chat/new-add-on-for-flexi...

:-)

-Steve