Function : Rex

The rex() function is the shortest form of fetching the direct string of a Compiler object rendered component. In this case, components are rendered with the Compiler object and the relative rendered string is returned.

Assuming we have a template file within the template directory "windows/Rex" named "home.rex.php" as below:
  The boy is {{ $age }} years today
                  

We can use the rex() function as shown below:
  <?php 

  namespace spoova/mi/windows/Routes/Home;

  use window;

  class Home extends Window { 


    function __construct() {

      //fetch template string
      $templateString = rex('home', fn() => compile(['age' => 13]));

      var_dump( $templateString );


    }


  }
                  

In the sample above, the rendered component will be returned as a string. We don't have to use the compile() function unless an argument is needed to be parsed. We can also directly display the rendered components as shown below:

  <?php 

  namespace spoova/mi/windows/Routes;

  use window;

  class Home extends Window { 


    function __construct() {

      //render template string
      echo rex('home', fn() => compile(['age' => 13]) );

    }


  }
                  

The essence of this method is to enable the subjection of rendered component to extended functionality. For some reason, if we need this functionality from a compiler object, the compiler class has a rex() method that directly returns the string of a compiled component. So, rather than use the approach above, we can address this similary using a better approach below :
  <?php 

  namespace spoova/mi/windows/Routes;

  use window;

  class Home extends Window { 


    function __construct() {

      //fetch template string
      $string = compile('home', ['age' => 13])->rex();

      var_dump($string);

    }


  }