Download the PHP package hxgf/slime-render without Composer
On this page you can find all versions of the php package hxgf/slime-render. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download hxgf/slime-render
More information about hxgf/slime-render
Files in hxgf/slime-render
Package slime-render
Short Description PHP abstraction functions to help more easily render views for Slim Framework with Handlebars (LightnCandy).
License MIT
Homepage https://github.com/jyoungblood/slime-render
Informations about the package slime-render
SLIME Render
PHP abstraction functions to help more easily render views for Slim Framework (v4) with plain text, HTML, JSON, and Handlebars (using LightnCandy)
These functions aim to provide a simplified and standardized interface for rendering various types of data-driven responses as PSR-7 objects for use with Slim.
Included with the Slime boilerplate for Slim applications.
Installation
Easy install with composer:
Requirements
- Slim Framework 4
- LightnCandy >= 1.2.6
- PHP >= 7.4
Usage
render::html($request, $response, $string, $status = 200)
Renders a string as HTML. Returns a standard Slim (PSR-7) response object with optional HTTP status code (200 by default).
Additionally, a path to an HTML file can be specified to load and render instead of a string:
render::text($request, $response, $string, $status = 200)
Renders a string as plain text. Returns a standard Slim (PSR-7) response object with optional HTTP status code (200 by default).
render::hbs($request, $response, $parameters, $status = 200)
Renders a specific Handlebars template with an array of data, including any partials and global locals
variables array. Returns a standard Slim (PSR-7) response object with optional HTTP status code (200 by default).
The parser function expects templates to be in a templates
directory with html
file extension. This can be customized by defining these variables in a global settings
array:
Additionally, an array of locals
can be added to make variables available across all templates:
Parameters from PHP $_GET and $_POST variables are automatically made available to templates rendered with this function, using the variables {{GET}}
and {{POST}}
:
Check out the Handlebars Cookbook to see everything you can do with LightnCandy and Handlebars.
Additionally, we've included a couple of helper functions.
The date
helper applies the PHP date()
function to a given variable or string (or now
keyword for the current time)
The #is
block helper allows for basic conditional logic:
Custom helpers are easy to create. Take a look at how these helpers are defined in initialize_handlebars_helpers(). The Handlebars cookbook also has a reference for creating custom helpers and custom block helpers.
render::handlebars($parameters)
Renders a specicific Handlebars template with data array the same as render::hbs()
, but returns raw html instead of a PSR-7 response.
render::redirect($request, $response, $string, $status = 302)
Renders a redirect as standard Slim (PSR-7) response object with optional HTTP status code.
render::json($request, $response, $data, $status = 200)
Renders an array or data as standard Slim (PSR-7) response object with application/json
content type and optional HTTP status code.
render::lightncandy_html($parameters)($data)
Prepares and compiles a specific Handlebars template with an array of data, including any partials and global locals
variables array.
This is automatically called by render::hbs()
but can be used as a standalone function if desired.
render::initialize_handlebars_helpers()
For internal use by lightncandy_html()
. Defines a couple custom Handlebars helper functions to be used by the LightnCandy compiler.