1. Go to this page and download the library: Download carawebs/sage-blade-data 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/ */
carawebs / sage-blade-data example snippets
namespace App;
use \Carawebs\SageBladeData\Loader;
use \Carawebs\SageBladeData\Filters;
// Optionally, see https://github.com/Carawebs/wp-metadata-accessor
use \Carawebs\DataAccessor\PostMetaData;
/**
* Load Controllers
*/
add_action('wp', function() {
new Loader(new Filters, new PostMetaData);
});
namespace Carawebs\Controllers;
use Carawebs\SageBladeData\Controller;
/**
*
*/
class FrontPage extends Controller
{
// Data available on 'home' and 'page' templates:
public function targetTemplates()
{
return ['home', 'page'];
}
public function dataToReturn()
{
$carouselSubfields = [
'image' => ['image_ID', 'full'],
'description'=>'text'
];
return [
// Post metadata from https://github.com/Carawebs/wp-metadata-accessor
// You can just access using ACF functions or similar.
'pageIntro' => $this->postMeta->getField('metafield'),
'intro' => $this->postMeta->getField('intro'),
'carouselData' => $this->postMeta->getRepeaterField('slider', $carouselSubfields),
];
}
}
class About extends Controller
{
public function targetTemplates()
{
return ['about'];
}
public function dataToReturn()
{
return [
'intro' => "Hello World",
];
}
}
BASH
composer dump-autoload
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.