jyoungblood / slime-render Goto Github PK
View Code? Open in Web Editor NEWPHP abstraction functions to help more easily render views for Slim Framework with Handlebars (LightnCandy).
License: MIT License
PHP abstraction functions to help more easily render views for Slim Framework with Handlebars (LightnCandy).
License: MIT License
Something along the lines of "you can use shared layouts with templates in other contexts...like sending emails, for example"
My particular use case involving email_send from x-utilities (I use this pattern all the time)
\VPHP\x::email_send([
'to' => '[email protected]',
'from' => '"'.$_ENV['SITE_TITLE'].'" <notifications@'.$_ENV['MAILGUN_DOMAIN'].'>',
'subject' => 'This email uses a template!',
'html' => true,
'message' => render::handlebars([
'layout' => '_layouts/email',
'template' => 'email/new-donation',
'data' => [
'donation' => $donation,
'donor' => $donor
]
])
]);
Basically an abstraction for rendering a template with render::hbs()
or render::html()
. It would use a general error template to show messages and error codes determined by the controller, and of course send the HTTP status code with the response.
Yes the design is stolen from the default Next.js error page.
We started working with a similar concept in dw 0.6. See the base route/controller setup (the $errorMiddleware->setErrorHandler
part) and general error template for more details.
It's similar to how many frameworks (Django, Express, Laravel, etc) handle layouts so it's nothing super unique...I just think it's worth describing in the readme.
Essentially: "define a layout template, any new html generated by the controller will be rendered into the {{outlet}}
tag," show a simple example, and link to the slime boilerplate base layout template.
Might also want to note which "global" variables will be rendered on the base template ({{title}}
, {{locals}}
, {{GET}}
, etc)
Probably best to do this as a separate package, but at some point I'd love to see more HBS helpers.
For inspiration: Assembly has a HUGE library of custom helpers for the JS version of handlebars, and BigCommerce's theme engine (Stencil) also has a good collection of helpers.
I also wrote a handful of helpers for js back in the day, idk if any of them would still be useful: https://github.com/hxgf/lexxi-handlebars/blob/master/index.js
It's easy enough to build custom helpers now, so we'd just need to make PHP versions of these.
Questions:
Want to show simple examples of:
If nothing else, link to relevant parts of slime-demo
Add a couple simple examples to the readme, basically a copy of what's in the initialize_handlebars_helpers() function:
$GLOBALS['hbars_helpers']['date'] = function ($arg1, $arg2, $arg3 = false) {
if (isset($arg1) && $arg1 != ''){
if ($arg1 == "now"){
return date($arg2);
}else{
if ($arg3 == "convert"){
return date($arg2, strtotime($arg1));
}else{
return date($arg2, $arg1);
}
}
}else{
return false;
}
};
Except we'd want a really simple function that could be copy/pasted.
Want to have an example of both a regular and block helper.
We have a group of global (site-wide) variables that are available by default for every template that is rendered. They need to be grouped in their own array/namespace and "locals" seemed like a good name at the time.
I feel like there's a more fitting term we could use, though, that more accurately conveys the nature of these variables and how they relate to the rest of the application.
HBS is great (and really the only kind of templates I care about), but I'm wondering if it would be helpful to provide these same kinds of abstractions for other template languages?
I'm specifically thinking:
There are more (HAML, Pug, Nunjucks, Smarty, Golang, etc) but I don't want to get carried away.
If so, we'd probably need to add some instructions for installing the supporting rendering packages.
What do you think? Cool idea? Too much? Sound off in the comments!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.