Skip to content

Make withTemplates() accept folder references and in-memory declarations#31

Merged
thekid merged 1 commit intomasterfrom
feature/templates-args
Mar 2, 2025
Merged

Make withTemplates() accept folder references and in-memory declarations#31
thekid merged 1 commit intomasterfrom
feature/templates-args

Conversation

@thekid
Copy link
Copy Markdown
Member

@thekid thekid commented Mar 2, 2025

Follows the "be liberal in what you accept" paradigm:

Loading templates from files

use com\handlebarsjs\{HandlebarsEngine, FilesIn};
use io\{Path, Folder};

$engine= (new HandlebarsEngine())->withTemplates(new FilesIn('src/main/handlebars'));

// All of these now also work:
$engine= (new HandlebarsEngine())->withTemplates('src/main/handlebars');
$engine= (new HandlebarsEngine())->withTemplates(new Path('src/main/handlebars'));
$engine= (new HandlebarsEngine())->withTemplates(new Folder('src/main/handlebars'));

Declaring templates in memory

use com\github\mustache\InMemory;
use com\handlebarsjs\HandlebarsEngine;

$declaration= ['test' => 'Hello {{name}}'];
$engine= (new HandlebarsEngine())->withTemplates(new InMemory($declaration));

// This now also works:
$engine= (new HandlebarsEngine())->withTemplates($declaration);

@thekid thekid merged commit c0628d5 into master Mar 2, 2025
20 checks passed
@thekid thekid deleted the feature/templates-args branch March 2, 2025 10:13
@thekid
Copy link
Copy Markdown
Member Author

thekid commented Mar 2, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant