Skip to content
Grav 2.0 is officially stable. Read the announcement →
Archive

Auto load new posts automatically

Started by Muut Archive 11 years ago · 3 replies · 316 views
11 years ago

When a new page/post is published, what would the AJAX look like to automatically display the post on the posts page?

11 years ago

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.

11 years ago

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.

11 years ago

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.

1) 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 the blog.html.twig file except return a pure JSON format with the json_encode Twig function

2) To use the JSON version rather than the html version of 'blog' template, simply request it: http://yoursite.com/blog.json

3) You will need to use JavaScript to use the JSON data and build your list of pages or notifications.

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1323 9 years ago
Archive · by Muut Archive, 9 years ago
2 919 9 years ago
Archive · by Muut Archive, 9 years ago
2 4048 9 years ago
Archive · by Muut Archive, 9 years ago
1 2923 9 years ago
Archive · by Muut Archive, 9 years ago
3 1106 9 years ago