Error handling 如何在以下场景中使用smarty模板中的变量?

Error handling 如何在以下场景中使用smarty模板中的变量?,error-handling,django-templates,smarty,Error Handling,Django Templates,Smarty,我的代码如下: {if $question_detail.question_has_sub_ques=='yes' && $question_detail.sub_question} {foreach from=$question_detail.sub_question item=sub_ques_ans key=sub_ques_no} <tr class="oddRow"> <td class="question"&g

我的代码如下:

{if $question_detail.question_has_sub_ques=='yes' && $question_detail.sub_question}
      {foreach from=$question_detail.sub_question item=sub_ques_ans key=sub_ques_no}
      <tr class="oddRow">
        <td class="question">
          <h4><strong>Sub-question {$page_question_no+1}.{$sub_ques_no+1}</strong></h4>
          <ul class="options">
            <li><span>{$sub_ques_ans.question_text}</span></li>
          </ul>
        </td>
        <td class="question-id">QUE{$sub_ques_ans.question_id}</td>
      </tr>
        {if $sub_ques_ans.question_file!=''}
      <tr>
        <td valign="top" colspan="2">
          <img src="{$ques_thum_image_path}{$sub_ques_ans.question_id}_{$sub_ques_ans.question_file}">
        </td>
      </tr>
        {/if}
        {if $question_detail.sub_question_answer_1}
      <tr class="question_answer evenRow">
        <td class="question">
          <p class="answers"><strong>Answers</strong></p> 
          <ol class="options">
          {foreach from=$question_detail.sub_question_answer_1 item=sub_ans key=sub_ans_no}
            <li>
            {if $sub_ans.answer_is_right==1} {assign var='correct_sub_ans' value=$sub_ans_no+1} {/if}
            {if $sub_ans.answer_text!=''}{$sub_ans.answer_text}{/if}<br />
            {if $sub_ans.answer_file!=''}<img src="{$ans_thumb_img_path}{$sub_ans.answer_id}_{$sub_ans.answer_file}" >{/if}
            </li>  
          {/foreach}
          </ol>
          <p class="correct-answer"><strong>Correct Answer Option : </strong>{$correct_sub_ans}</p>
        </td>
        <td class="question-id">&nbsp;</td>
      </tr>
        {/if}  
      {/foreach}
    {/if}
但是它有错误,我可以知道正确使用它的方法吗?提前谢谢。

试试这个

    {assign var="condition" value="{$question_detail.sub_question_answer}_{$page_question_no+1}"}
    {if $condition}
     // do your code
    {/if}

像这样的方法会奏效:

{$curr_answer = 'sub_question_answer_'|cat:($page_question_no+1)}

{if $question_detail.$curr_answer}

您是否尝试过
{if$question\u detail.sub\u question\u answer\u($page\u question\u no+1)}
{$curr_answer = 'sub_question_answer_'|cat:($page_question_no+1)}

{if $question_detail.$curr_answer}