Search code examples
pythoncherrypymako

Concatenate string MAKO


This is my code of Mako but I have the error when i use this code with my server Cherrypy. The error is

SyntaxException: (SyntaxError) invalid syntax (<unknown>, line 1) (u"c=inputp${k}_id\nsomeval= ${urld['kwargs']['${c}']}") in file '/home/user/Scaricati/prototypefin/template/web_editor_parameter_settings.html' at line: 164 char: 1

When i wrong with this code? I have to try, if there is a relevant value and print its contents

    <div id="sortparam" >

<%
    k = 1
    a=99
%>
<ul  class="ui-sortable" id="sorpara">
    % for k in a:
        <% 
        c=inputp${k}_id
        someval= ${urld['kwargs']['${someval}']} 
        %>
        % if someval is UNDEFINED:
                    <% break %> 
        %     else:
<li id="inputp${id}_id" class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s"></span>${someval}</li>

        %     endif
        % endfor
  </ul>
</div>

Ah I miss what is the variable kwargs?? Kwargs is the content the my file

{'demo_title': 'Demo title', 'demo_input_description': 'hola mundo ', 'demo_params_description': '  ', 'demo_wait_description': ' ', 'demo_result_description': '  ', 'images_config_file': 'cfgmydemo.cfg', 'demo_data_filename': 'data_saved.cfg', 'tag': '', 'inputdata1_id': 'id_lsd', 'inputdata1_max_pixels': '1024000' }

Where i wrong??


Solution

  • Try with this code:

    <div id="sortparam" >
    
    <%
        k = 1
        a=99
    %>
    <ul  class="ui-sortable" id="sorpara">
        % for k in a:
            <% 
            c='inputp'+k+'_id' 
            %>
            % if c in urld['kwargs'] :
    
    <li id="inputp${k}_id" class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s"></span>${urld['kwargs']['${c}']}</li>
    
            %     endif
            % endfor
      </ul>
    </div>