We all like working with schemas, and it's frustrating that it's not
obvious how to use them on pages that face the public.
To make this easier, we've added a tiny feature that allows you to ask
Apostrophe to load all the CSS and JS a logged-in user would get.
This saves you the trouble of using apos.requireScene, a nifty but
tricky piece of frontend code that tends to break because we honestly
don't use it often enough in our own work.
The new, simple technique is this:
Just set...
req.scene = 'user';
... In a page loader function.
If you want it all the time for your whole site, you can do it in a
project level page loader function that doesn't actually care what
req.page is. However, keep in mind that it does take some time to load
extra CSS and JS on a page, and so it's usually best to choose to use
schemas on relevant pages, such as donation pages, purchase pages,
etc.
"Wait, how do I use schemas in my own code in the first place?"
Good question. The schemas module documentation has the answer:
https://www.npmjs.com/package/apostrophe-schemas
You can also check out the apostrophe-donate module for a great
example of using schemas independently, to handle public-facing forms:
https://www.npmjs.com/package/apostrophe-donate
There's an apos.requireScene call in apostrophe-donate for backwards
compatibility. So just keep in mind that you can set req.scene on the
server side instead, and it's a simpler and less risky strategy that
we'll be following in A2 0.6.
--
THOMAS BOUTELL, DEV & OPS
P'UNK AVENUE |
(215) 755-1330 |
punkave.com