galileo_twig_dart

Last updated:

0 purchases

galileo_twig_dart Image
galileo_twig_dart Images
Add to Cart

Description:

galileo twig dart

twig_dart #


galileo
support for
twig.
Installation #
In your pubspec.yaml:
dependencies:
galileo_twig: ^3.0.0
copied to clipboard
Usage #
Just like mustache and other renderers, configuring galileo to use
twig is as simple as calling app.configure:
import 'package:galileo_framework/galileo_framework.dart';
import 'package:galileo_twig/galileo_twig.dart';
import 'package:file/file.dart';

galileoConfigurer myPlugin(FileSystem fileSystem) {
return (galileo app) async {
// Connect twig to your server...
await app.configure(
twig(fileSystem.directory('views')),
);
};
}
copied to clipboard
package:galileo_twig supports caching views, to improve server performance.
You might not want to enable this in development, so consider setting
the flag to app.isProduction:
twig(viewsDirectory, cacheViews: app.isProduction);
copied to clipboard
Keep in mind that this package uses package:file, rather than
dart:io.
The following is a basic example of a server setup that can render twig
templates from a directory named views:
import 'package:galileo_framework/galileo_framework.dart';
import 'package:galileo_twig/galileo_twig.dart';
import 'package:file/local.dart';
import 'package:logging/logging.dart';

main() async {
var app = new galileo();
var fileSystem = const LocalFileSystem();

await app.configure(
twig(fileSystem.directory('views')),
);

// Render the contents of views/index.twig
app.get('/', (res) => res.render('index', {'title': 'ESKETTIT'}));

app.use(() => throw new galileoHttpException.notFound());

app.logger = new Logger('galileo')
..onRecord.listen((rec) {
print(rec);
if (rec.error != null) print(rec.error);
if (rec.stackTrace != null) print(rec.stackTrace);
});

var server = await app.startServer(null, 3000);
print('Listening at http://${server.address.address}:${server.port}');
}
copied to clipboard
To apply additional transforms to parsed documents, provide a
set of patch functions, like in package:twig_preprocessor.

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.