Latest Site Updates Twig Config

Hi, I have a large site and the homepage is quite a important area for me to list the latest updates to the website i.e. new articles. I was wondering if their was a way to automate this via twigs?

Currently once the article is created and I want it to appear in the homepage I have to edit the homepage md with the information in order for it to appear. Not quite sure how I go about having the twig changed so it automatically updates the homepage.

http://www.houseofbhangra.com on the right you have sidebar and theirs also tabs with lyrics.

So in order to add new lyrics I have to edit sidebar.md and add in the info + homepage.md and add in the info.

Wondering if this can be done automatically so that the information is contained in the article.md and appears in both those locations as its a new/modified page.

I looked at the find in pages my issue is that I have sub folders for all the sections and not sure how to make find it pages looks at sub folders too. So new article added in category “lyrics” subfolder “aman hayer”, another article added into “singh” not sure how find pages can target sub folders of the main folder.

It’s actually easier to do it in PHP, so that means creating a plugin to do it. I can give you an example taken straight from the admin that lists the latest modified pages, but you could change this to be based on the page date:

    public function latestPages($count = 10)
    {
        /** @var Pages $pages */
        $pages = $this->grav['pages'];

        $latest = array();

        foreach ($pages->routes() as $url => $path) {
            $page = $pages->dispatch($url);
            if ($page && $page->routable()) {
                $latest[$page->route()] = ['modified' => $page->modified(), 'page' => $page];
            }
        }

        // sort based on modified
        uasort($latest, function ($a, $b) {
            if ($a['modified'] == $b['modified']) { 
                return 0;
            }

            return ($a['modified'] > $b['modified']) ? -1 : 1;
        });

        // build new array with just pages in it
        // TODO: Optimized this
        $list = array();
        foreach ($latest as $item) {
            $list[] = $item['page'];
        }

        return array_slice($list, 0, $count);
    }

Basically all you would have to do is to create a class with this method, assign an instance of that class to a twig variable, then simply call it via twig:

<ul>
{% for latest in admin.latestPages %}
    <li><a href="{{ latest.url }}"><i class="fa fa-fw fa-file-o"></i> {{ latest.title }}</a></td><td class="double">{{ latest.route }}</td><td><b>{{ latest.modified|nicetime }}</b></li>
{% endfor %}
</ul>