The Trongate PHP Framework
Documentation
Introduction
Quick Start
Basic Concepts
Understanding Routing
Controllers
Views
Assets
Modules Calling Modules
Parent & Child Modules
Database Operations
Modules within Modules
Templates & Themes
Helpers Explained
Form Handling
Working with Files
The Module Import Wizard
Authorization & Authentication
The API Explorer
Best Practices

Help Improve Our Docs

If you’ve found an error, spotted something missing, or feel a section could be clearer or better explained, we’d love to hear from you. Your feedback helps keep the documentation accurate and useful for everyone.

Please report issues or suggest improvements on GitHub. Community input is invaluable in making the docs stronger.

Not comfortable with GitHub? No problem — you can also get in touch with us directly via our contact form. We welcome all feedback.

Returning View Output as a Variable

To capture the rendered output of a view file as a string variable in Trongate, developers can utilize the third argument of the view() method. This approach is useful when the output needs to be manipulated or processed further before being sent to the output stream.

Example Usage

Consider a scenario where you want to capture the HTML output of a 'information.php' view file:

The code sample above demonstrates capturing the rendered output of a view file and returning the view file output as a PHP variable named, '$html'.

Step-by-Step Guide

  1. Step 1: Assign the result of the view() method to a variable:
  2. Step 2: Include the boolean value true as the third parameter to return the output as a string:
  3. Step 3: Complete the method by returning the newly created variable:

If no data array is available when calling the view, simply pass an empty array (as a second argument) followed by the boolean, true:

This technique effectively returns the view content as a string, facilitating flexible handling within the application.

×