PHP code example of lotfio / caprice

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

    

lotfio / caprice example snippets


    composer 

    composer test


  use Caprice\Caprice;

  

  // load caprice predefined directives
  $caprice->loadPredefinedDirectives();

  // set views location and cache location
  $caprice->setCompileLocations('views', 'cache'); 

  // helpful for development environment
  $caprice->enableRecompile();
  
  // file to compile  => views/test.cap.php
  // you can remove .cap.php extension for both
  $compiled = $caprice->compile("test");

  


    // simple directives
    $caprice->directive("#test", function(){
        return 'replace test directive with this string';
    });

    // expression directive
    // example #call($var)
    $caprice->directive("#call", function(string $expression, string $match, array $extras){
        return ' call'. $expression . ';
cpp
    #php
        $var1 = "foo";
        $var2 = "bar";
        echo $var1 . " and " . $var2;
    #endphp
cpp
    #if ($condiftion)
     // if logic

    #elseif ($condition2)

      // elseif logic
    #else
      // else logic
    #endif
cpp
    // for in loop key only
    #for ($name in $array)
        {{ $name }}
    #endforin
cpp
    // for in loop key value
    #for ($name => $age in $array)
        {{ $name }} => {{ $age }}
    #endforin
cpp
    // functions
    // dump
    #dump($variable) OR #dd($variable)