When a new page/post is published, what would the AJAX look like to automatically display the post on the posts page?
I’m not sure I’m understanding you properly. Grav handles the logic to automatically display a page when it is published. If you set a date, the cache timeout is calculated so that the cache expires right when the page publish/unpublish state changes, so that the next person to load the page, will see the correct and updated state.
There is no Ajax happening here. It’s just a matter of Grav calculating the current time, and determining if the page should be displayed or not.
I want to create a ‘news feed’ style site with new pages in a certain folder/category counting as a notification. I’d like it so that users don’t have to refresh and instead new notifications appear on the page. I’m only assuming this would have to be done with Ajax.
That’s a pretty custom setup your asking about. It’s not really a support question I can answer here, more like custom development. However, I can point you in the right direction.
-
To use Ajax, you need to decide how you want to get the data dynamically. Usually a good bet is JSON, and for that you can just create a twig template of the format:
blog.json.twig
and then do similar logic as theblog.html.twig
file except return a pure JSON format with the json_encode Twig function -
To use the JSON version rather than the html version of ‘blog’ template, simply request it:
http://yoursite.com/blog.json
-
You will need to use JavaScript to use the JSON data and build your list of pages or notifications.