Inspired by jQuery

We enjoy working with the jQuery javascript library because its syntax is simple and fun to use, and it lets you get a lot done without a lot of work. We've always wished that we could find a similar experience with a CMS platform. As a result, ProcessWire's API is inspired by jQuery and its style and syntax.

The goal behind the ProcessWire API is to provide the level of accessibility and control to your site's pages that jQuery provides to the DOM.

That being said, there are fundamental differences in the way that PHP and Javascript work, not to mention even greater fundamental differences between an SQL database and the DOM. As a result, ProcessWire's CMS API is merely inspired by jQuery and there are as many differences as similarities. But my hope is that if you like jQuery, you'll find ProcessWire's API familiar and easy to work with. Even if you haven't worked with jQuery, the API is designed to be easy and approachable, and its scope is smaller than that of jQuery's (easier to learn).

What’s similar to jQuery?

DOM / Site Map
You interact with your site's structure via ProcessWire's API in a manner similar to working with the DOM in jQuery. The hierarchy of your site can be thought of like a DOM hierarchy, where every node (page) has a parent and every node may have children, and so on. Likewise, every node (page) can have its own attributes (fields). Depending on the type of node (template) the attributes (fields) will be different.

Methods
For the most part, ProcessWire's CMS API attempts to use the same method naming conventions as jQuery. For example, you may use the find(), children(), siblings(), parent() and parents() methods on any page (aka node) and optionally supply a selector. Read More

Selectors
ProcessWire takes the idea of attribute selectors from jQuery and lets you apply that methodology to getting and finding pages in your site based on values in their attributes (aka fields). These selectors are a simplified version of what you find in jQuery, but the intention, experience and results are the same. For the most part, the operators used in a selector are the same as the operators used in jQuery selectors. More about Selectors

Chaining
Like in jQuery, you can chain method calls in ProcessWire if you want to (fluent interface).

Traversing
Like in jQuery, most traversing methods return values that can themselves be traversed and compared. For instance, a call to $page->find(...) or $page->children(...) returns an array type that also has its own methods for find(), filter(), first(), has(), add(), filter() and so on.

Comments

  • Soma

    Posted by Soma on Feb 11, 2013 3:27 PM

    This got me interested.

  • Grant

    Posted by Grant on Feb 11, 2014 3:19 PM

    Thank you for reminding people it's called "fluent interface" :)

Post a Comment

Your e-mail is kept confidential and not included with your comment. Website is optional.