Q:

search in array and return parent node with smarty in prestashop

Good day all.
I'm writing a module, I'm in the .tpl at the moment, and I'm trying to retrieve the language id for the current page I'm displaying. Actually I'm working on some test code, to know if I have all the elements to go on.
I have this so far :
id={$smarty.get.id_category}
id_language = {$smarty.get.id_lang}
{assign var=my_lang_id value=$smarty.get.id_lang}
my_lang_id= {$my_lang_id}    
languages = {$languages|@print_r}

and actually, i'm getting:
id=7
id_language = 6
my_lang_id= 6
languages = Array
(
    [0] => Array
        (
            [id_lang] => 1
            [name] => English (English)
            [active] => 1
            [iso_code] => en
            [language_code] => en-us
            [date_format_lite] => m/j/Y
            [date_format_full] => m/j/Y H:i:s
            [is_rtl] => 0
            [id_shop] => 1
            [shops] => Array
                (
                    [1] => 1
                )

        )

    [1] => Array
        (
            [id_lang] => 6
            [name] => Italiano (Italian)
            [active] => 1
            [iso_code] => it
            [language_code] => it
            [date_format_lite] => d/m/Y
            [date_format_full] => d/m/Y H:i:s
            [is_rtl] => 0
            [id_shop] => 1
            [shops] => Array
                (
                    [1] => 1
                )

        )

    [2] => Array
        (
            [id_lang] => 7
            [name] => English (United Kingdom)
            [active] => 1
            [iso_code] => gb
            [language_code] => gb
            [date_format_lite] => d/m/Y
            [date_format_full] => d/m/Y H:i:s
            [is_rtl] => 0
            [id_shop] => 1
            [shops] => Array
                (
                    [1] => 1
                )

        )

    [3] => Array
        (
            [id_lang] => 8
            [name] => English (Australia)
            [active] => 1
            [iso_code] => au
            [language_code] => en-au
            [date_format_lite] => d/m/Y
            [date_format_full] => d/m/Y H:i:s
            [is_rtl] => 0
            [id_shop] => 1
            [shops] => Array
                (
                    [1] => 1
                )

        )

    [4] => Array
        (
            [id_lang] => 9
            [name] => English (Canada)
            [active] => 1
            [iso_code] => ca
            [language_code] => en-ca
            [date_format_lite] => d/m/Y
            [date_format_full] => d/m/Y H:i:s
            [is_rtl] => 0
            [id_shop] => 1
            [shops] => Array
                (
                    [1] => 1
                )

        )

)

My problem is... I would like to retrieve the iso_code of my current language, and the iso_code and language_code of a given language, from this array... let's say I would like to have "it", "it" as my current language id is 6, and then I would like to get the id_lang of the language with iso_code = en is that possible? or i'm getting the wrong way?

A:

Here's the way you can compare it using smarty:
PHP test file:
$languages = array();
$languages[] = array('id_lang' => 1, 'iso_code' => 'en', 'language_code' => 'en-us');
$languages[] = array('id_lang' => 6, 'iso_code' => 'it', 'language_code' => 'it');
$languages[] = array('id_lang' => 7, 'iso_code' => 'gb', 'language_code' => 'gb');
$smarty->assign('languages',$languages);

Smarty test file:
{assign var=my_lang_id value=6}

{foreach $languages as $lang}
    {if $lang.id_lang eq $my_lang_id}
       {$lang.iso_code} {$lang.language_code}
    {/if}
{/foreach} 

I hope that's what you needed because I don't know prestashop at all.

