PHP code example of flexpress / component-layout

1. Go to this page and download the library: Download flexpress/component-layout 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/ */

    

flexpress / component-layout example snippets


$pimple['ACFHelper'] = function ($c) {
    return new ACFHelper($c['objectStorage'], $c['objectStorage'], array(), array(
        $c["flexibleLayoutProxy"]
    ));
};

class HelloWorld extends AbstractLayout {
  
  public function getLabel() {
    return "Hello world";
  }
  
  public function getMarkup() {
    echo "<p>Hello world</p>";
  }
  
}

$pimple["helloWorldLayout"] = function() {
  return new HelloWorld();
};

$pimple["layoutController"] = function ($c) {
    return new LayoutController(array(
      // Add your layouts here
      $c["helloWorldLayout"]
    ));
};

class HelloUniverse extends AbstractLayout {
  
    public function getLabel() {
        return "Hello universe";
    }
    
    public function getMarkup() {
        echo "<p>Hello universe</p>";
        if($this->field['fp_show_time']) { 
            echo "<p>", date(), "</p>";
        }
        
    }
    
    // make the layout only available on pages
    public function isAvailableOn($post_id) {
        return get_post_type($post_id) == 'page';
    }
  
    // to get this array, export a acf field group and grab everything in 'fields' => array(...etc
    public function getFields() {
        return array (
            array (
                'key' => 'field_53b132d9363ec',
                'label' => 'Show time',
                'name' => 'fp_show_time',
                'type' => 'true_false',
                'message' => '',
                'default_value' => 0
            )
        );
    }
  
}