Instead of printing directly, the viewer's HTML can be captured into PHP variables and echoed wherever you need — handy for templating engines.

Supplying values. Load the template, resolve its variables, assign the application values, and render or display the updated report.
<?php
require_once '../vendor/autoload.php';

use Stimulsoft\Report\StiReport;
use Stimulsoft\Viewer\StiViewer;


// Creating a viewer object and set the necessary javascript options
$viewer = new StiViewer();
$viewer->javascript->relativePath = '../';

// Processing the request and, if successful, immediately printing the result
$viewer->process();

// Creating a report object
$report = new StiReport();

// Loading a report by URL
// This method does not load the report object on the server side, it only generates the necessary JavaScript code
// The report will be loaded into a JavaScript object on the client side
$report->loadFile('../reports/SimpleList.mrt');

// Assigning a report object to the viewer
$viewer->report = $report;

// Getting the necessary JavaScript code and visual HTML part of the viewer
$js = $viewer->javascript->getHtml();
$html = $viewer->getHtml();
?>

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <link rel="shortcut icon" href="../favicon.ico" type="image/x-icon">
    <title>Showing a Report in the Viewer in an HTML template using PHP variables</title>
    <style>
        html, body {
            font-family: sans-serif;
        }
    </style>

    <?php
    // Printing the necessary JavaScript code of the viewer
    echo $js;
    ?>
</head>
<body>
<h2>Showing a Report in the Viewer in an HTML template using PHP variables</h2>
<hr>
<?php
// Printing the visual HTML part of the viewer
echo $html;
?>
</body>
</html>



getHtml() returns the markup as a string rather than printing it, so you can store the scripts and the viewer body in variables and insert them into any layout or template system.

By using this website, you agree to the use of cookies for analytics and personalized content. Cookies store useful information on your computer to help us improve efficiency and usability. For more information, please read the privacy policy and cookie policy.