PHP code example of moxie-lean / loader

1. Go to this page and download the library: Download moxie-lean/loader 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/ */

    

moxie-lean / loader example snippets


// functions.php


// File: index.php
use Lean\Load;

$args = [
  'title' => get_the_title(),
  'url' => get_the_permalink(),
  'target' => '_blank'
];
Load::partials( 'single', $args );

 
// File: partials/single.php 
// All loaded files have an $args variable that is used to store all the params
// passed from where the Load function was used.

 
use Lean\Load;

$set_1 = [
  'a' => 1,
  'b' => 5,
  'c' => 3
];
$set_2 = [
  'a' => 10,
  'd' => 3
];
$set_3 = [
  'd' => 10,
  'c' => 2,
  'r' => 3,
];
// You can have as many sets as you want.
Load::partials( 'single', $set_1, $set_2, $set_3 ) 


// File: partials/single.php

// The following lines creates an array with default values. If those values 
// are not specified when the file is loaded this values are going to be used instead.
$defaults = [
  'url' => '',
  'title' => '',
  'target' => '_self',
]
// Update $args with the initial $args mixed with the $default values.
$args = wp_parse_args( $args, $defaults );


// File: partials/single.php

// The following lines creates an array with default values. If those values 
// are not specified when the file is loaded this values are going to be used instead.
$defaults = [
  'url' => '',
  'title' => '',
  'target' => '_self',
]
// Update $args with the initial $args mixed with the $default values.
$args = wp_parse_args( $args, $defaults );

// Don't render if the title or url are empty.
if ( empty( $args['title'] || empty( $args['url'] ) ) ) {
  return; 
}

 
use Lean\Load;

$arguments = [];
Load::views( 'partials/single', $arguments ); 
Load::views( 'partials/button', $arguments ); 

add_filter( 'loader_directories', function( $directories ){
  $directories[] = get_template_directory() . '/views';
  return $directories;
});

 
use Lean\Load;

$arguments = [];
Load::partials( 'single', $arguments ); 
Load::partials( 'button', $arguments ); 

add_filter('loader_alias', function( $alias ){
  $alias['partials'] = 'blocks';
  return $alias;
});


use Lean\Load;
$arguments = [];
Load::blocks( 'single', $arguments );

index.php
functions.php
|- views
|-|- partials
|-|-|- single.php
|-|-|- button.php