Airtable collection model
With Pages you can also create your own Collection Models. Example here with Airtable
https://github.com/joomlatools/joomlatools-pages/discussions/623
WARNING: Do not share your API key with anyone (including anyone at Airtable) since it's effectively a password that allows access to all your bases. If you accidentally reveal your API key, you should regenerate your API key as soon as possible at https://airtable.com/account
Note: For this example, I created two (linked) tables on Airtable
Considerations about caching
Note: I have created a "Last Modified" automatic column in Airtable. But beware: rename the column "lastModified" bc it is named so in the Airtable Collection Model.
My observation
There is a cache file in /cache/airtable (that I deleted manually in order to force a refresh after Airtable source was changed
But even when I add the following to the frontmatter the cache seems to never refresh
@process:
cache: false
Explanation by Johan
Different kind of cache. There is a cache for the data that is retrieved from Airtable, that cache is updated in the background, to turn it off you need to set the global http_client_cache to false. I wouldn’t do that though, because then pages needs to fetch the data from airtable for each time you request data friom the airtable model. This cache is updated in the background.
By adding a lastModified field to your Airtable, you make pages smarter so it can know when an individual row in the Airtable has been changed or not, see in the Airtable Collection Model:
//Check if the database has a lastModified column
if(!$this->_hash_key && array_key_exists('lastModified', $data[0])) {
$this->_hash_key = array('lastModified');
}
This code handles that.
The
@process:
cache: false
handles the output caching of the actually generated html page. Turn this off and the page is re-generated for each request, this is what Joomla does.
Here is a practical example with Airtable
See the original data on https://airtable.com/shrz6XLIz7DJDEsIE
Notes: Title 1 (same picture)
Autonumber: 1
Status: Done
createdTime: 2021-07-06T13:47:46.000Z
Feature (first and second from array): Custom Fields | (no second one)
Thumbnail (small)::
Notes: Title 2
Autonumber: 2
Status: In progress
createdTime: 2021-07-06T13:47:46.000Z
Feature (first and second from array): Access Control Lists | Workflow
Thumbnail (small)::
Notes: Title 3
Autonumber: 3
Status: Todo
createdTime: 2021-07-06T13:47:46.000Z
Feature (first and second from array): Custom Fields | Workflow
Thumbnail (small)::
Notes: Title 4 (new picture)
Autonumber: 4
Status: Done
createdTime: 2021-11-07T09:38:56.000Z
Feature (first and second from array): Custom Fields | (no second one)
Thumbnail (small)::
And here is a little print_r
of each $item of the collection so that you can see all what is immediately available in the array itself:
ComPagesModelEntityItem Object
(
[id] => recW0OLcKuYZ9rZXW
[createdTime] => 2021-07-06T13:47:46.000Z
[Status] => Done
[Table 2] => Array
(
[0] => recw3uL9E7DERhcMW
)
[Notes] => Title 1 (same picture)
[Attachments] => Array
(
[0] => Array
(
[id] => attcL2WLi8NQ7KnOO
[width] => 3264
[height] => 2176
[url] => https://dl.airtable.com/.attachments/36a2a43923312d6ba934b620543355f1/c17522e8/alex-vasey-3lxrM5yvkcI-unsplash.jpg
[filename] => alex-vasey-3lxrM5yvkcI-unsplash.jpg
[size] => 1363391
[type] => image/jpeg
[thumbnails] => Array
(
[small] => Array
(
[url] => https://dl.airtable.com/.attachmentThumbnails/f7a04c5d597adf29684d4b26d90ea513/6b83f085
[width] => 54
[height] => 36
)
[large] => Array
(
[url] => https://dl.airtable.com/.attachmentThumbnails/5f4ecf2da1e3d592e08c6c7005a5e919/6331c6c5
[width] => 768
[height] => 512
)
[full] => Array
(
[url] => https://dl.airtable.com/.attachmentThumbnails/ce52878fd5e14e03c37ec916210f59ec/7b614685
[width] => 3000
[height] => 3000
)
)
)
)
[Autonumber] => 1
[Feature (from Table 2)] => Array
(
[0] => Custom Fields
)
[lastModified] => 2021-11-07T17:20:07.000Z
[ordering] => 1
)
ComPagesModelEntityItem Object
(
[id] => rec78lEJJo7T6fXdd
[createdTime] => 2021-07-06T13:47:46.000Z
[Status] => In progress
[Table 2] => Array
(
[0] => recvfnANGwMmbqnV3
[1] => rec2iyBI1jtLJbZaM
)
[Notes] => Title 2
[Attachments] => Array
(
[0] => Array
(
[id] => attJHkcvFqhYQZmdS
[width] => 640
[height] => 427
[url] => https://dl.airtable.com/.attachments/efb310c4e2da4a2893d1774c5ee2d7ad/97d12157/alex-shutin-kKvQJ6rK6S4-unsplash.jpg
[filename] => alex-shutin-kKvQJ6rK6S4-unsplash.jpg
[size] => 16741
[type] => image/jpeg
[thumbnails] => Array
(
[small] => Array
(
[url] => https://dl.airtable.com/.attachmentThumbnails/58db6e3a693d3a1d36d93f6cce2d02bc/fd059a20
[width] => 54
[height] => 36
)
[large] => Array
(
[url] => https://dl.airtable.com/.attachmentThumbnails/01d5a5e5ca6e8bbfdd567536ae0e5a3e/471a89cb
[width] => 640
[height] => 427
)
[full] => Array
(
[url] => https://dl.airtable.com/.attachmentThumbnails/b94796bfcf7392a362ea5aaf7d3aa380/39436955
[width] => 3000
[height] => 3000
)
)
)
)
[Autonumber] => 2
[Feature (from Table 2)] => Array
(
[0] => Access Control Lists
[1] => Workflow
)
[lastModified] => 2021-11-06T10:17:48.000Z
[ordering] => 2
)
ComPagesModelEntityItem Object
(
[id] => recxUNzg9519skVwX
[createdTime] => 2021-07-06T13:47:46.000Z
[Status] => Todo
[Table 2] => Array
(
[0] => recw3uL9E7DERhcMW
[1] => rec2iyBI1jtLJbZaM
)
[Notes] => Title 3
[Attachments] => Array
(
[0] => Array
(
[id] => att4Sp34RBvPGN1wm
[width] => 3872
[height] => 2592
[url] => https://dl.airtable.com/.attachments/f46be787ddcc0ad4aade3afb14fc9717/ea07336c/amador-loureiro-BVyNlchWqzs-unsplash.jpg
[filename] => amador-loureiro-BVyNlchWqzs-unsplash.jpg
[size] => 2016601
[type] => image/jpeg
[thumbnails] => Array
(
[small] => Array
(
[url] => https://dl.airtable.com/.attachmentThumbnails/81fc4d0ef3ac95f8469c1d42c8da33bb/d3a2afb1
[width] => 54
[height] => 36
)
[large] => Array
(
[url] => https://dl.airtable.com/.attachmentThumbnails/400f131a63fdc99b107f59cd2f17c6c4/ea943c7d
[width] => 765
[height] => 512
)
[full] => Array
(
[url] => https://dl.airtable.com/.attachmentThumbnails/8d9d6c19d898dee348fb26475ba70887/0c89b6da
[width] => 3000
[height] => 3000
)
)
)
)
[Autonumber] => 3
[Feature (from Table 2)] => Array
(
[0] => Custom Fields
[1] => Workflow
)
[lastModified] => 2021-07-07T12:07:56.000Z
[ordering] => 3
)
ComPagesModelEntityItem Object
(
[id] => receN4YqZSnuKN43X
[createdTime] => 2021-11-07T09:38:56.000Z
[Status] => Done
[Table 2] => Array
(
[0] => recw3uL9E7DERhcMW
)
[Notes] => Title 4 (new picture)
[Attachments] => Array
(
[0] => Array
(
[id] => attPLfcbib1blFIzK
[width] => 1900
[height] => 1068
[url] => https://dl.airtable.com/.attachments/3125b1c83e5dc21716a2611fd9b1d221/a8bf0270/alex-vasey-zmbxbdg4qbc-unsplashoptimized.jpg
[filename] => alex-vasey-zmbxbdg4qbc-unsplash optimized.jpg
[size] => 210879
[type] => image/jpeg
[thumbnails] => Array
(
[small] => Array
(
[url] => https://dl.airtable.com/.attachmentThumbnails/836f476e59692c20278b6525325b5ba8/1ea68271
[width] => 64
[height] => 36
)
[large] => Array
(
[url] => https://dl.airtable.com/.attachmentThumbnails/94939594d9984f4faa15e65622be07f6/8964cfce
[width] => 911
[height] => 512
)
[full] => Array
(
[url] => https://dl.airtable.com/.attachmentThumbnails/71ff29ea4f512007f4b6b353106db871/31956fc6
[width] => 3000
[height] => 3000
)
)
)
)
[Autonumber] => 4
[Feature (from Table 2)] => Array
(
[0] => Custom Fields
)
[lastModified] => 2021-11-07T17:19:39.000Z
[ordering] => 4
)