How to suppress quotes as HTML entities?

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

returns as:

selected="selected"

which is an invalid HTML attribute of course.

How to 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>

Thank!

+3
source share
1 answer

according to the Mojolicious web framework docs you will need to add, and extra = at <% = for printing in raw format.

<%= $selected %>

will be

<%== $selected %>

for more help 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>
+5
source

Source: https://habr.com/ru/post/1752599/


All Articles