Reputation: 12957
The array $data which is assigned to smarty template is as follows:
Array
(
[pt_id] => 2
[pt_doc_title] => Happy New Year
[pt_doc_id] =>
[delete_flag] =>
[pt_doc_file_iname] => array.txt
)
To assign it to smarty template I used following code line:
$smarty->assign('data', $data);
Now currently this array is containing only one element but there may be more such elements into this array as the array is going to be generated dynamically. So for accessing the values I wrote following code, but I'm not getting anymore values over there.
{foreach from=$data item=titles key=key}
<li id="ttl{$key+1}" class="ans_li">
<span class="num-block">{$key+1} </span>
<label>{'Document Title'|signal_on_error:$error_msg:'correct_ans'} <span class="reqd"> * </span></label>
<input type="text" name="pt_doc_title[{$key+1}]" id="pt_doc_title_{$key+1}" value="{$titles.pt_doc_title}">
<p class="uploadBtn"><input type="file" name="document_file_name_{$key+1}" id="document_file_name_{$key+1}">
</p>
{if $titles.pt_doc_file_iname!= ""}
<a href="package_type_documents.php?op=download&pt_id={$titles.pt_id}&pt_doc_id={$titles.pt_doc_id}" style="font-size:small;">{$titles.pt_doc_file_iname}</a>
<input type="checkbox" name="delete_file_{$key+1}" id="delete_file_{$key+1}" class="custom-check" />
<label for="show">Delete file</label>
{else}
<p class="custom-form">
<a href="#" id="ttl{$key+1}" onclick="delete_title(this.id);return false;" class="c-delete">Delete</a>
</p>
{/if}
<input type="hidden" name="pt_doc_id[{$key}]" value="{$titles.pt_doc_id}">
{if $titles.pt_doc_file_iname!=''}
<input type="hidden" name="pt_doc_file_iname[{$key}]" value="{$titles.pt_doc_file_iname}">
{/if}
</li>
{/foreach}
So am I making any mistake in accessing the above array in smarty? Please help me in correcting my issue. Thanks in advance.
Upvotes: 0
Views: 148
Reputation: 24468
Try using a multidimensional array for your array.
Something like this.
$data = array
(
0 => array(
'pt_id' => 2,
'pt_doc_title' => 'Happy New Year',
'pt_doc_id' => ,
'delete_flag' => ,
'pt_doc_file_iname' => 'array.txt'
)
1 => array(
'pt_id' => 3,
'pt_doc_title' => 'Some other title',
'pt_doc_id' => ,
'delete_flag' => ,
'pt_doc_file_iname' => 'array2.txt'
)
)
$smarty->assign('data', $data);
Upvotes: 1