2.0+
Bond variables
Pass Variables
Bond components are capable of accessing direct template variables when they are passed into the bond directive. The bond component controller must however have a public property with the supplied variable name in order to be able to access the variable. When the template is rendering, the variables passed will be rendered along with the bond component.

  bond('Posts', [ 'name' => 'foo' ])
                              
  namespace spoova/mi/windows/Bond;

  use spoova/mi/core/classes/Bond;

  class Posts extends Bond{

    public $name;

    public function render(): Compiler|String {

      return <<<compile
      <div> 

        {{ $name }} //foo

      </div>
      compile;

    }


  }  
                              


Overide Pass Variables
When varibles are passed, they can be overidden from the bond component controller by setting the value of the relative public property.

  bond('Posts', [ 'name' => 'foo' ])
                              
  namespace spoova/mi/windows/Bond;

  use spoova/mi/core/classes/Bond;

  class Posts extends Bond{

    public $name = 'bar';

    public function render(): Compiler|String {

      return <<<compile
      <div> 

        {{ $name }} //bar

      </div>
      compile;

    }


  }  
                              


Default Variables
It is not mandated to pass variables only from the directive, we can also set default values from the bond component controller. These will be rendered along with the main template file.

  bond('Posts')
                              
  namespace spoova/mi/windows/Bond;

  use spoova/mi/core/classes/Bond;

  class Posts extends Bond{

    public $name = "foo";

    public function render(): Compiler|String {

      return <<<compile
      <div>
      
        {{ $name }} //foo
      
      </div>
      compile;

    }


  }
                              

Inherit Variables
Variable are automatically inherited when they are passed from main compiler engine and it is not essential to re-parse them in bond directives even when it is possible.

  <?php 

  namespace spoova/mi/windows/Routes;

  use Window;

  class Home extends Window{

    public function root() {

      self::load('rex-template', fn() => compile(['name' => 'foo']) );

    }


  }
                              

rex-template
  bond('Posts')
                              
bond controller
  namespace spoova/mi/windows/Bond;

  use spoova/mi/core/classes/Bond;

  class Posts extends Bond{

    public function render(): Compiler|String {

      return compile('bond-component', fn() => compile());

    }


  }
                              
bond-component
  <div>
  The name is {{ $name }}
  </div>
                              
In the sample above, the bond component will inherit the parent compiler variables without having to pass the variable into the bond directive unless it is overridden by a public property.