|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
macfreakz Smarty Rookie
Joined: 23 Aug 2004 Posts: 7
|
Posted: Tue Aug 24, 2004 3:16 pm Post subject: Assoc arrays: Why doesn´t this work? |
|
|
php file:
[php:1:ac9c9e4f7d]
$menus = array("menu1" => array("News", "terms"), "menu2" => array("information", "rules"), "menu3" => array("Links"));
$smarty->assign('menus', $menus);
[/php:1:ac9c9e4f7d]
tpl file:
Code: |
{foreach key=k item=value from=$menus}
<b>{$value[menu1]}</b>
{/foreach}
|
Why doesn´t this work?
It outputs only:
Instead this I wanna get:
|
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Tue Aug 24, 2004 3:57 pm Post subject: |
|
|
inside your foreach loop, $k will be the key 'menu1' and $value will be the array ('News','terms')
So one way to access the data:
Code: | {foreach key=k item=value from=$menus}
key is {$k}
array item 1 is {$value[0]}
array item 2 is {$value[1]}
{/foreach} |
Or, you could loop through your value array:
Code: | {foreach key=k item=value from=$menus}
key is {$k}
{foreach item="foobar" from=$value}
item is {$foobar}
{/foreach}
{/foreach} |
|
|
Back to top |
|
macfreakz Smarty Rookie
Joined: 23 Aug 2004 Posts: 7
|
Posted: Wed Aug 25, 2004 7:00 am Post subject: |
|
|
Thats not the solution!
But I found the right solution:
Code: | {foreach key=k item=value from=$menus[menu1]}
<b>{$value}</b>
{/foreach} |
And I forgot to delete the compiled file which was used as cache file to open the page faster! I dont want to have this option. How can I disable the cache? |
|
Back to top |
|
dthought Smarty Regular
Joined: 21 Apr 2003 Posts: 55 Location: Melbourne, Australia
|
Posted: Wed Aug 25, 2004 7:02 am Post subject: |
|
|
Normally if you just edit and resave a TPL file, Smarty picks up on it and recompiles it... only if something odd is going on will it not recompile. |
|
Back to top |
|
macfreakz Smarty Rookie
Joined: 23 Aug 2004 Posts: 7
|
Posted: Wed Aug 25, 2004 7:15 am Post subject: |
|
|
@dtought: oh yeah! I now understand why my files are not recompiled after changing the content: the templates are stored on the database.
I implemented this function:
[php:1:992921ce88]
function db_get_timestamp($tpl_name, &$tpl_timestamp, &$smarty_obj)
{
return true;
}
[/php:1:992921ce88]
Thats wrong! This function should return the update time of the content. I have to plan how to implement this function now ... Help anyone? |
|
Back to top |
|
macfreakz Smarty Rookie
Joined: 23 Aug 2004 Posts: 7
|
Posted: Wed Aug 25, 2004 8:15 am Post subject: |
|
|
Uh, I have the solution with timestamp:
[php:1:5d69eca04b]
function db_get_timestamp($tpl_name, &$tpl_timestamp, &$smarty_obj)
{
global $db; // default db id
$sqlquery = "SHOW TABLE STATUS LIKE 'tbl_template'";
$tbl_info_result = mysql_query($sqlquery, $db) or die ("Error: ".mysql_error($db));
$tbl_info_data = mysql_fetch_array($tbl_info_result);
$tpl_timestamp = strtotime($tbl_info_data['Update_time']);
return true;
}
[/php:1:5d69eca04b] |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|