eozzy
eozzy

Reputation: 68680

How to suppress quotes output as HTML entities?

$selected = ' selected="selected"'
# or
$selected = qq( selected="selected")

is returned as:

selected="selected"

which is an invalid HTML attribute, ofcourse.

How do I fix it?

Edited to add:

<select name="alignment" class="select" 
    <%== param('feature') ? '' : 'disabled'; %>
>
% foreach (keys %al) {
%  my $selected = param('aligment') && param('aligment') eq $_ ? ' selected' : '';
%
%  if (!param('aligment') && $_ eq 'left') { $selected = ' selected' }
%
    <option value="<%=$_%>" <%= $selected %>>
     <%= $al{$_} %>
    </option>
%        
% }
</select>

Thanks!

Upvotes: 3

Views: 313

Answers (1)

Prix
Prix

Reputation: 19528

according to Mojolicious web framework documents you would need to add and extra = at <%= in order to print it in raw format.

<%= $selected %>

would be

<%== $selected %>

for more reference you can read this http://github.com/kraih/mojo/blob/master/lib/Mojolicious/Guides/Rendering.pod

try like this:

<select name="alignment" class="select" 
    <%== param('feature') ? '' : 'disabled'; %>
>
% foreach (keys %al) {
%  my $selected = param('aligment') && param('aligment') eq $_ ? ' selected' : '';
%
%  if (!param('aligment') && $_ eq 'left') { $selected = ' selected' }
%
<option value="<%=$_%>"
 <%= $selected %>
>
     <%= $al{$_} %>
    </option>
%        
% }
</select>

or

<select name="alignment" class="select" 
    <%== param('feature') ? '' : 'disabled'; %>
>
% foreach (keys %al) {
%  my $selected = param('aligment') && param('aligment') eq $_ ? ' selected="selected"' : '';
%
%  if (!param('aligment') && $_ eq 'left') { $selected = ' selected="selected"' }
%
<option value="<%=$_%>"
 <%== $selected %>
>
     <%= $al{$_} %>
    </option>
%        
% }
</select>

Upvotes: 5

Related Questions