-
I'm not sure if I am thinking about template rendering backwards compared to everyone else but bare (no pun intended) with me. I have a set of application "modules" which basically just represent all the views that a user can navigate to. My way of thinking of this is to have each module render its main "content" for the page and buffer that output. The module would also have a way to be able to flex the page container and determine which "layout" the page should have that wraps the main "content". My thought was to have a after router middleware that I pass to <?php
use Leaf\App;
require __DIR__ . '/vendor/autoload.php';
$app = new App();
$app->get('/', function () {
print '<h1>Hello from server root</h1>';
});
$app->get('/template', function () {
print app()->template->render('template');
});
$app->run(function() {
print app()->template->render('default.main', [
'app' => app(),
'content' => ob_get_clean()
]);
}); I don't think this is how most people thinking of templating but I was trying to save myself from having a boilerplate in every "module" that renders the main template and provide a way for the "module" to alter the wrapper template that is used. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Well, I apologize as it seems the issue must not be related to BareUI or Leaf. My template that is showing the issue runs a simple query with doctrine/dbal and then outputs some very simple HTML. Commenting out the database query and hard-coding an array to mimic the results of the query appears to eliminate the problem. How very strange as I would think the querying is all synchronous... Here's the gist of the template that exhibits the problem. I'm open to any ideas as to what might be causing the behavior. <?php
use Doctrine\DBAL\DriverManager;
$db = DriverManager::getConnection([
'dbname' => 'my-db',
'user' => 'username',
'password' => 'supersecretpassword',
'host' => 'localhost',
'driver' => 'mysqli'
]);
$strsql =
'SELECT
*
FROM
link_groups lg
JOIN link_group_items lgi ON
lgi.link_group_id = lg.id
and lgi.active = 1
WHERE
lg.group_name = ?
ORDER BY lgi.order_num, lgi.item_desc';
$links = $db->executeQuery($strsql, ['myViews'])->fetchAllAssociative();
?>
<ul>
<?php foreach ($links as $link) { ?>
<li><a href="<?= $link['item_link'] ?>"><?= $link['item_desc'] ?></a></li>
<?php } ?>
</ul> Here's a screenshot showing the end result in the browser where the stuff that should be in the |
Beta Was this translation helpful? Give feedback.
-
Ignore me. Embarrassed because I tried even this... The problem was indeed with the output buffering. I indeed do need to call |
Beta Was this translation helpful? Give feedback.
Ignore me. Embarrassed because I tried even this... The problem was indeed with the output buffering. I indeed do need to call
ob_start()
myself because if I don't then the default output buffer is used which is flushed automatically after 4,096 bytes are reached. So it was just the amount of data that my query/view was outputting that caused the buffer to be flushed automatically. Oy vey. 😥