Closed rayblair06 closed 1 month ago
@rayblair06 do you think it's worth adding something like this?
public function shareWithViews(string $key, $value): void
{
$this->sharedViewData[$key] = $value;
}
public function view(...$params): ResponseInterface
{
// Merge shared data with view-specific data
$viewData = array_merge($this->sharedViewData, $params[1] ?? []);
$params[1] = $viewData;
// ...
}
@notrab would this be to share global variables across views?
$app->get("/", function ($context) {
$context->shareWithView('user', [
'username' => 'Ray'
]);
...
});
$app->get("/foo", function ($context) {
// Would have access to user['username'] without having to pass it?
$context->view('view', []);
});
@notrab would this be to share global variables across views?
$app->get("/", function ($context) { $context->shareWithView('user', [ 'username' => 'Ray' ]); ... }); $app->get("/foo", function ($context) { // Would have access to user['username'] without having to pass it? $context->view('view', []); });
I thought anyway @rayblair06 but perhaps it's not the best idea. Let
In this PR, you'll find examples of how Dumbo could render views using template engines like Blade, Latte, Twig, or really any template engine, all within the Context service. Let me know your thoughts!