tree - How to create an unlimited depth category subcategory select box in smarty -


i trying create select box containing unlimited depth category , sub category select box. have array contains unlimited category sub category depth shown below,

                    array                     (                         [0] => array                             (                                 [id] => 6                                 [cata_key] => 32e9c75e38d2a1d77b2b49b2                                 [cata_name] => road                                 [app_key] => b80e0935b348da61b2a807ff                                 [parentid] => 0                                 [subcategories] => array                                     (                                         [0] => array                                             (                                                 [id] => 9                                                 [cata_key] => 780c3eb53264d5c33a26d49f                                                 [cata_name] => cars                                                 [app_key] => b80e0935b348da61b2a807ff                                                 [parentid] => 6                                                 [subcategories] => array                                                     (                                                         [0] => array                                                             (                                                                 [id] => 10                                                                 [cata_key] => 111cd06b1575457f665d460e                                                                 [cata_name] => hyundai                                                                 [app_key] => b80e0935b348da61b2a807ff                                                                 [parentid] => 9                                                                 [subcategories] => array                                                                     (                                                                     )                                                              )                                                          [1] => array                                                             (                                                                 [id] => 11                                                                 [cata_key] => 26ca0e1622c11ed2628eaadf                                                                 [cata_name] => maruthi                                                                 [app_key] => b80e0935b348da61b2a807ff                                                                 [parentid] => 9                                                                 [subcategories] => array                                                                     (                                                                     )                                                              )                                                      )                                              )                                          [1] => array                                             (                                                 [id] => 16                                                 [cata_key] => 49973084640af71ad61e634b                                                 [cata_name] => bikes                                                 [app_key] => b80e0935b348da61b2a807ff                                                 [parentid] => 6                                                 [subcategories] => array                                                     (                                                     )                                              )                                      )                              )                          [1] => array                             (                                 [id] => 7                                 [cata_key] => 56bae4297efcbf796b230a99                                 [cata_name] => river                                 [app_key] => b80e0935b348da61b2a807ff                                 [parentid] => 0                                 [subcategories] => array                                     (                                         [0] => array                                             (                                                 [id] => 12                                                 [cata_key] => 7fc72e49fe67d0b777648f54                                                 [cata_name] => boat                                                 [app_key] => b80e0935b348da61b2a807ff                                                 [parentid] => 7                                                 [subcategories] => array                                                     (                                                         [0] => array                                                             (                                                                 [id] => 14                                                                 [cata_key] => 38c749056a9f583e284e509b                                                                 [cata_name] => 2 seater                                                                 [app_key] => b80e0935b348da61b2a807ff                                                                 [parentid] => 12                                                                 [subcategories] => array                                                                     (                                                                     )                                                              )                                                          [1] => array                                                             (                                                                 [id] => 15                                                                 [cata_key] => 6ebfcad4d4e05e84d333b7e5                                                                 [cata_name] => 10 seater                                                                 [app_key] => b80e0935b348da61b2a807ff                                                                 [parentid] => 12                                                                 [subcategories] => array                                                                     (                                                                     )                                                              )                                                      )                                              )                                          [1] => array                                             (                                                 [id] => 13                                                 [cata_key] => b6125c73f6d7c153f45e133e                                                 [cata_name] => ship                                                 [app_key] => b80e0935b348da61b2a807ff                                                 [parentid] => 7                                                 [subcategories] => array                                                     (                                                     )                                              )                                      )                              )                          [2] => array                             (                                 [id] => 8                                 [cata_key] => 1c748603f36105b921b54165                                 [cata_name] => air                                 [app_key] => b80e0935b348da61b2a807ff                                 [parentid] => 0                                 [subcategories] => array                                     (                                     )                              )                      ) 

i create select box in tpl visitor select proper category / sub category. in advance

you can use smarty 3 , functions in case

php:

$smarty->assign("you_category_array", **$you_array**); 

smarty:

{function name=menu level=0}   <ul class="level{$level}">   {foreach $data $category}     {if is_array($category.subcategories)}       <li>{$category.cata_name}       {menu data=$category.subcategories level=$level+1}</li>     {else}       <li>{$category.cata_name}</li>     {/if}   {/foreach}   </ul> {/function}  {menu data=$you_category_array} 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -