Function : View

The view() function renders template file in a slightly different way and does not return the compiler object because files are sliced directly using a template slicer tool which returns a string of rendered components. Template files in this case are rendered directly with parsed arguments and the resultant template string is returned. In most cases, the returned string have to be subjected to further processing which is why the template string returned may most likely be dependent on the window self::load() method.

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 pass the "$age" value to the template file and have it loaded through the view() function as shown below:
  <?php 

  namespace spoova/mi/windows/Routes/Home;

  use window;

  class Home extends Window { 


    function __construct() {

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

      // The boy is 13 years today
      self::load( 'home', fn() => $templateString );

    }


  }
                  

When parameters are passed into the view() function, they are usually saved temporarily for immediate use. In a short and close cycle, this can become an advantage for placeholders. Hence, a template file of the format below may still work.

  The boy is {{ $age }} years today
                  
  <?php 

  namespace spoova/mi/windows/Routes/Home;

  use window;

  class Home extends Window { 


    function __construct() {

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

      // The boy is 13 years today
      self::load( 'home', fn() => $templateString );

    }


  }
                  

When rendering components, it is preferrable to use functions that truly renders template component through the compiler object. These methods are the compile() and rex() functions.