Using JSON-T (JSON Templates) with AJAX on Squarespace
Often developers need to make custom widgets for Squarespace using AJAX. But what if you want to use comfort templating (with all Squarespace predicates and formatters) which you already have built-in - JSON-T? Squarespace use it on backend and on front too. Earlier it was in sqs-commerce.js module and also you may try to use their custom Y.Handlebars for templating. But personally I found previous module more comfort to use so I just borrowed it into one file we need. You may download this file:
So I'll show how to create custom query module with templating. I used similiar technique to create Recent Comments Plugin. This is useful for custom collections or when you need to show something out of scope - for example I use <squarespace:navigation/> to access collections out of url scope, but in this case items of collections are not available.
Well, first of all we just need include grabbed module:
Let's keep all things simple and use next markup for our query:
Then we need to use template for our query. But need to change curly braces, because server will try to render this. I just changed the first one.
Now we need script for get collection data by url, render it and insert result to page.
That's all folks, please share and subscribe for new posts!