https://github.com/mudler/mojolicious-plugin-viewbuilder
a Mojolicious plugin that allows to chain templates generated by other plugins
https://github.com/mudler/mojolicious-plugin-viewbuilder
Last synced: 9 months ago
JSON representation
a Mojolicious plugin that allows to chain templates generated by other plugins
- Host: GitHub
- URL: https://github.com/mudler/mojolicious-plugin-viewbuilder
- Owner: mudler
- License: other
- Created: 2014-09-06T16:22:22.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2015-01-26T23:03:29.000Z (over 11 years ago)
- Last Synced: 2025-10-10T20:32:13.902Z (9 months ago)
- Language: Perl
- Size: 195 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: Changes
- License: LICENSE
Awesome Lists containing this project
README
[](https://travis-ci.org/mudler/Mojolicious-Plugin-ViewBuilder)
# NAME
Mojolicious::Plugin::ViewBuilder - a Mojolicious plugin that allows to chain templates generated by other plugins
# SYNOPSIS
#Load the plugin
# - Mojolicious
$self->plugin('ViewBuilder');
# - Mojolicious::Lite
plugin 'ViewBuilder';
# then, use it in your template, declare a new area, labeled "profile"
<%= pluggable_view 'profile' %>
# now, in the plugin, that will attach the new helper to the view
sub register {
my ( $self, $app, $conf ) = @_;
$app->helper(
test => sub {
shift->render_to_string( "test", some_data => 1 );
}
);
#attach the test helper to the view "profile"
$app->add_view( "profile", "test" );
}
1;
# or you can append a callback
sub register {
my ( $self, $app, $conf ) = @_;
$app->add_view(
profile => sub {
shift->render_to_string( "test", some_data => 42 );
}
);
}
1;
__DATA__
@@ test.html.ep
huuuray!
% if( stash("some_data") and stash("some_data")==42){
double it!
% }
# DESCRIPTION
[Mojolicious::Plugin::ViewBuilder](https://metacpan.org/pod/Mojolicious::Plugin::ViewBuilder) is a [Mojolicious](https://metacpan.org/pod/Mojolicious) plugin. Chains templates generated by other plugins, associating them within the view. This is useful only if your workflow is to reap into little pieces the webapp (e.g. in plugins)
# METHODS
[Mojolicious::Plugin::ViewBuilder](https://metacpan.org/pod/Mojolicious::Plugin::ViewBuilder) inherits all methods from
[Mojolicious::Plugin](https://metacpan.org/pod/Mojolicious::Plugin) and implements the following new ones.
## pluggable\_view
<%=pluggable_view "profile" %>
Will render all the attached plugin associated within the view
## add\_view
$app->add_view("view","helper");
$app->add_view(view => sub{shift->render_to_string("Hello mojolicious!")});
Attach the "helper" within the "view"
# LICENSE
Copyright (C) mudler.
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
# AUTHOR
mudler