Coder Social home page Coder Social logo

slime-render's Issues

Docs - Add another example of one-off rendering with render::handlebars()

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
      ]
    ])
  ]);

New render::error() Function (with default 'error' templates)

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.

Add description and example of how base (layout) parsing works

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)

More HBS Helpers!

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:

  • Are there any changes we'd want to make in how we're initializing the helpers?
  • Instead of a separate package, would it be better to just have these available as copypastas in some docs somewhere?

Add example of how to build & initialize custom HBS helpers

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.

Consider alternate term for "locals"

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.

Add support for other templating languages

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!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.