-
Hello, I have this kind of
Is there any way I can do something similar to:
I tried to put
It always return something like
No errors though... I would like it on the template side, because easier to edit for a colleague than Perl code, but if not possible, I would take any other suggestion. Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
One solution to my own question could be to pass
Also, after reading the docs, I found out that a helper would surely be the way to go... |
Beta Was this translation helpful? Give feedback.
-
Created a helper that I load in the app: use Mojo::Base 'Mojolicious::Plugin', -signatures;
sub register ( $self, $app, $conf ) {
$app->helper(
style => sub ( $self, $key ) {
return $app->config->{ css }->{ $key }->%*;
});
} I have a
Then managed to consume it this way:
It produce the nice: <table bgcolor="#FFFFFF" border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td>
<span>Mojo :D</span>
</td>
</tr>
</tbody>
</table> Like it! |
Beta Was this translation helpful? Give feedback.
-
The idea of using the configuration system for this was awful because you need to restart the app each time you change something manually. I just replaced this by a normal module that I use Mojo::Base -base, -signatures;
use constant {
WHITE => '#FFFFFF',
MAIN_WIDTH => 600,
CELLZERO => {
cellpadding => '0',
cellspacing => '0',
},
};
sub css {
return {
body => {
leftmargin => '0',
topmargin => '0',
marginwidth => '0',
marginheight => '0',
},
'top-table' => {
bgcolor => WHITE,
width => '100%',
border => '0',
CELLZERO->%*,
},
'content-table' => {
align => ' center',
gbcolor => WHITE,
width => MAIN_WIDTH,
CELLZERO->%*,
},
}
}
1; The helper now looks like: use Mojo::Base 'Mojolicious::Plugin', -signatures;
use Foo::Plugin::Style::CSS;
sub register ( $self, $app, $conf ) {
my $style = Alerts::Api::Plugin::Style::CSS->new;
$app->helper(
inline => sub ( $self, $key ) {
return $style->css->{ $key }->%*;
});
}
Seems like more reasonable. The good thing is that it makes possible to reuse a lot of those things from the |
Beta Was this translation helpful? Give feedback.
The idea of using the configuration system for this was awful because you need to restart the app each time you change something manually. I just replaced this by a normal module that I
use
in the helper.