All Projects → protonemedia → laravel-blade-on-demand

protonemedia / laravel-blade-on-demand

Licence: MIT License
Compile Blade templates in memory

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to laravel-blade-on-demand

laravel-miniprogram-poster
Use Laravel to building a miniprogram poster.
Stars: ✭ 72 (+100%)
Mutual labels:  laravel-package
searchable
Pattern-matching search and reusable queries in laravel.
Stars: ✭ 28 (-22.22%)
Mutual labels:  laravel-package
laravel-crud-generator
Laravel CRUD Generator
Stars: ✭ 181 (+402.78%)
Mutual labels:  laravel-package
devtube
Laravel YouTube and Online Video viewing and download interface.
Stars: ✭ 30 (-16.67%)
Mutual labels:  laravel-package
laravel-bitcoinrpc
Bitcoin JSON-RPC Service Provider for Laravel.
Stars: ✭ 83 (+130.56%)
Mutual labels:  laravel-package
shield
A laravel middleware to protect against unverified webhooks from 3rd party services.
Stars: ✭ 96 (+166.67%)
Mutual labels:  laravel-package
artisan-cloudflare
Laravel artisan commands for CloudFlare
Stars: ✭ 67 (+86.11%)
Mutual labels:  laravel-package
csv
No description or website provided.
Stars: ✭ 47 (+30.56%)
Mutual labels:  laravel-package
active-state
Laravel Active State Url Helper For Request
Stars: ✭ 45 (+25%)
Mutual labels:  laravel-package
artisan-beans
Easily manage your Beanstalkd job queues right from the Laravel artisan command
Stars: ✭ 41 (+13.89%)
Mutual labels:  laravel-package
dropzoner
Laravel package for image upload using DropzoneJS
Stars: ✭ 46 (+27.78%)
Mutual labels:  laravel-package
phpcsfixer-preset
Use the same php-cs-fixer configuration across all of your projects, with presets for common project layouts (Laravel, Composer packages, etc.).
Stars: ✭ 22 (-38.89%)
Mutual labels:  laravel-package
magento-laravel-api
A simple Magento 2 REST API Object Oriented wrapper for Laravel applications.
Stars: ✭ 45 (+25%)
Mutual labels:  laravel-package
maintenance-mode
An enhanced maintenance mode for Laravel.
Stars: ✭ 117 (+225%)
Mutual labels:  laravel-package
larafeed
Laravel package for providing visual feedback via screenshots.
Stars: ✭ 42 (+16.67%)
Mutual labels:  laravel-package
panichd
Ticketing system for Laravel 5.1 - 8.x. Allows to create new tickets via form only. Includes file attachments, ticket tags, filtering, scheduling and e-mail notifications.
Stars: ✭ 78 (+116.67%)
Mutual labels:  laravel-package
laravel-sms-api
Laravel package to provide SMS API integration.
Stars: ✭ 84 (+133.33%)
Mutual labels:  laravel-package
laravel-string-similarities
Compare two string and get a similarity percentage
Stars: ✭ 54 (+50%)
Mutual labels:  laravel-package
laravel-dacapo
Laravel migration support tool, Always generate the latest migration files on schema.yml
Stars: ✭ 88 (+144.44%)
Mutual labels:  laravel-package
Base62
PHP Base62 encoder and decoder for integers and big integers with Laravel 5 support.
Stars: ✭ 16 (-55.56%)
Mutual labels:  laravel-package

Laravel Blade On Demand

Latest Version on Packagist run-tests Quality Score Total Downloads

Laravel package to compile Blade templates in memory. Requires PHP 7.4 or higher, compatible with Laravel 8 and 9.

Support

We proudly support the community by developing Laravel packages and giving them away for free. Keeping track of issues and pull requests takes time, but we're happy to help! If this package saves you time or if you're relying on it professionally, please consider supporting the maintenance and development.

Installation

You can install the package via composer:

composer require protonemedia/laravel-blade-on-demand

Usage

Render Blade template

You can render any valid Blade Template by calling the render method on the BladeOnDemand facade. The method only takes two parameters, the template content and the data you want to pass to the template.

$output = BladeOnDemand::render('Hello {{ $name }}', ['name' => 'Protone Media']);

echo $output;

// "Hello Protone Media"

This is a just an example but you can use statements, components and other Blade features as well.

Handle missing variables

This feature prevents your render from failing whenever a variable is missing in your data array. By default it will fill the missing variable with the name of the variable itself. In this case $name is missing so the data array becomes ['name' => 'name'];

$output = BladeOnDemand::fillMissingVariables()->render('Hello {{ $name }}', []);

echo $output;

// "Hello name"

You could also use this feature to preview a template without any data. Note that this might give unexpected results when using statements. You can also pass a callable to the fillMissingVariables method to customize the handling of missing variables:

$output = BladeOnDemand::fillMissingVariables(
    fn ($variable) => "_MISSING_{$variable}_MISSING_"
)->render('Hello {{ $name }}');

echo $output;

// "Hello _MISSING_name_MISSING_"

Render Markdown Mail to HTML

This feature can be used to render a mail as if you're using a Markdown mailable.

$contents = implode(PHP_EOL, [
    '@component("mail::message")',
    '# Hello {{ $name }}',
    '@endcomponent',
]);

$output = BladeOnDemand::renderMarkdownMailToHtml($contents, ['name' => 'Protone Media']);

echo $output;

// <!DOCTYPE>
// <html xmlns="http://www.w3.org/1999/xhtml">
// <head>
//     ...
// </head>
// <body>
// <style>
//     ...
// </style>

// <table>
//     ...
//     <h1>Hello Protone Media</h1>
//     ...
// </table>
// </body>
// </html>

You can optionally specify a theme, just like calling the theme method on a Mailable.

BladeOnDemand::theme('invoice')->renderMarkdownMailToHtml($contents, $data);

Render Markdown Mail to text

Similair feature as the above renderMarkdownMailToHtml method except it uses components from the text directory. You can read more about this feature in the Laravel documentation.

$contents = implode(PHP_EOL, [
    '@component("mail::message")',
    '# Hello {{ $name }}',
    '@endcomponent',
]);

$output = BladeOnDemand::renderMarkdownMailToText($contents, ['name' => 'Protone Media']);

echo $output;

// [AppName](http://localhost)
//
// # Hello Protone Media
//
// © 2020 AppName. All rights reserved.

Parse Maildown Mail

The parseMarkdownMail method is the same as the renderMarkdownMailToText method but it also parses the Markdown.

$contents = implode(PHP_EOL, [
    '@component("mail::message")',
    '# Hello {{ $name }}',
    '@endcomponent',
]);

$output = BladeOnDemand::parseMarkdownMail($contents, ['name' => 'Protone Media']);

echo $output;

// <p><a href="http://localhost">AppName</a></p>
// <h1>Hello Protone Media</h1>
// <p>© 2020 AppName. All rights reserved.</p>

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Other Laravel packages

  • Laravel Analytics Event Tracking: Laravel package to easily send events to Google Analytics.
  • Laravel Cross Eloquent Search: Laravel package to search through multiple Eloquent models.
  • Laravel Eloquent Scope as Select: Stop duplicating your Eloquent query scopes and constraints in PHP. This package lets you re-use your query scopes and constraints by adding them as a subquery.
  • Laravel FFMpeg: This package provides an integration with FFmpeg for Laravel. The storage of the files is handled by Laravel's Filesystem.
  • Laravel Form Components: Blade components to rapidly build forms with Tailwind CSS Custom Forms and Bootstrap 4. Supports validation, model binding, default values, translations, includes default vendor styling and fully customizable!
  • Laravel Mixins: A collection of Laravel goodies.
  • Laravel Paddle: Paddle.com API integration for Laravel with support for webhooks/events.
  • Laravel Verify New Email: This package adds support for verifying new email addresses: when a user updates its email address, it won't replace the old one until the new one is verified.
  • Laravel WebDAV: WebDAV driver for Laravel's Filesystem.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].