PHP code example of huncwotdev / twigflow

1. Go to this page and download the library: Download huncwotdev/twigflow library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

huncwotdev / twigflow example snippets


// application/modules/m_news_list.php
namespace App\Modules;

use App\Modules\BaseModule;
use App\Modules\ModuleProcessorInterface;

class m_news_list extends BaseModule implements ModuleProcessorInterface
{
    public function fetchData(array $module, array $data): array
    {
        // Return async HTTP requests; they run in parallel with other modules
        return [
            'articles' => $this->apiFetcher->asyncFetchFromApi(
                '*[_type == "article"] | order(publishedAt desc)[0..5]'
            )
        ];
    }

    public function process(array $module, array $asyncData): array
    {
        $module['articles'] = $asyncData['articles'] ?? [];
        return $module;
    }
}

// application/api/get/featured-posts.php
namespace App\Api;

class featured_posts
{
    public function process(array $params): array
    {
        // Return data; TwigFlow wraps it in {"status":"success","data":{...}}
        return ['posts' => []];
    }
}