NAME

Text::Nunjucks::Loader::FileSystem - 1:1 port of Nunjucks src/node-loaders.js FileSystemLoader -- templates from search paths on disk

VERSION

version 0.001

DESCRIPTION

Loads templates from directories on disk, a port of the FileSystemLoader of Nunjucks src/node-loaders.js. A template name is looked up in each search path in turn and the first file that exists is read as UTF-8 and returned.

use Text::Nunjucks::Environment;
use Text::Nunjucks::Loader::FileSystem;

my $loader = Text::Nunjucks::Loader::FileSystem->new( [ 'views', 'shared' ], { noCache => 1 } );
my $env    = Text::Nunjucks::Environment->new($loader);

search_paths

Array reference of the directories searched, in order.

no_cache

True when the Environment must not cache the templates this loader returns.

paths_to_names

Hash reference mapping the absolute path of each template the loader has read to the name it was asked for.

new

Text::Nunjucks::Loader::FileSystem->new;
Text::Nunjucks::Loader::FileSystem->new( $search_paths, \%opts );

Positional. $search_paths is a directory or an array reference of them; without it the search path is .. The options are a hash reference with one useful key, noCache: when true the templates are not cached and are read again on each lookup. A watch option that is true dies with a Text::Nunjucks::Lib::Error whose message is watch requires chokidar to be installed.

get_source

my $source = $loader->get_source($name);

Returns { src => $text, path => $absolute_path, noCache => $bool } for the first search path that holds the template, or undef when none does. A file is only found when its absolute path begins with the absolute search path, so ../outside.njk is not served from beyond the search path (the check is a string prefix test, which a sibling directory whose name starts with the search path's name passes). Emits load with the name and the source.

SUPPORT

Issues

Please report bugs and feature requests at https://github.com/Getty/p5-text-nunjucks/issues.

CONTRIBUTING

Contributions are welcome! Please fork the repository and submit a pull request.

AUTHOR

Torsten Raudssus <getty@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2026 by Torsten Raudssus <torsten@raudssus.de> https://raudssus.de/.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.