|
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 |
sadistic Smarty n00b
Joined: 22 Sep 2004 Posts: 4
|
Posted: Wed Sep 22, 2004 4:14 pm Post subject: Array Problem |
|
|
Wie spreche ich arrays in smarty an wenn der array key dynamisch sein soll?
$groups = array(1 => Mitglieder,
2 => Privat,
3 => usw..);
ich versuche folgendes
{$groups[$resume[result].group]}
{$group[1]} = Mitglieder (das geht)
$result[result].group kommt aus einer section schleife und gibt int zurück
nur beides kombiniert geht nicht kann mir da bitte wer helfen? |
|
Back to top |
|
kills Smarty Elite
Joined: 28 May 2004 Posts: 493
|
|
Back to top |
|
sadistic Smarty n00b
Joined: 22 Sep 2004 Posts: 4
|
Posted: Thu Sep 23, 2004 8:33 am Post subject: |
|
|
ich hab aber nicht ein array sondern 2
und das ergebnis des ersten arrays ($resume[result].group)
ist der schlüssel für das zweite array ($groups[])
und da steht leider kein beispiel auf der seite wie man ein array behandelt das ein zweites als key braucht
bitte kann mir wer ein beispiel geben?
thx im vorraus |
|
Back to top |
|
sadistic Smarty n00b
Joined: 22 Sep 2004 Posts: 4
|
Posted: Thu Sep 23, 2004 8:49 am Post subject: |
|
|
Hier mal der Code:
php-file
<?
include_once('../includes/ob_start.php');
require_once('../config/config.inc.php');
require_once('../classes/class_newsletter.php');
new newsletter(array('session', 'smarty_loader', 'resume', 'groups'), $class, true, true);
$smarty =& $class['smarty_loader']->smarty;
$smarty->assign('logo', HTML_LOGO);
$smarty->assign('appname', APPNAME);
$smarty->assign('groups', $class['resume']->getGroups());
$smarty->assign('resume', $class['resume']->getResumeData());
$smarty->display('admin_newsletter_resume.html');
include_once('../includes/ob_end.php');
?>
die zugewiesenen Arrays:
$groups = Array
(
[2] => Geschäftlich
[1] => Mitglieder
[3] => Privat
);
$resume = Array
(
[0] => Array
(
[id] => 12
[max_value] => 500
[value] => 267
[date] => 00.00.0000
[time] => 00:00:00
[prozent] => 53.40
[type] => text
[group] => 1
[subject] => kein subject
[message] => testmessage
)
);
und der auszug aus dem tpl file
{section name=result loop=$resume}
{if $resume[result].group eq ""}
Alle
{elseif $resume[result].group == "0"}
Keine Gruppe
{else}
// SO und hier besteht mein Problem
{$groups.resume.result.group} -> geht nicht
{$groups.$resume.result.group} -> geht nicht
{$groups[$resume[result].group]} -> geht nicht
{/if}
{/section}
wäre sehr nett wenn mir wer die lösung für dieses problem sagen könnte, dies ist leider mein erstes projekt mit smarty, und ne richtige beschreibung für dieses problem gibts nicht |
|
Back to top |
|
sadistic Smarty n00b
Joined: 22 Sep 2004 Posts: 4
|
Posted: Thu Sep 23, 2004 10:05 am Post subject: |
|
|
Code: |
{if $resume[result].group eq ""}
Alle
{elseif $resume[result].group == "0"}
Keine Gruppe
{else}
{foreach name=gr key=key item=value from=$groups}
{if $key eq $resume[result].group}
{$value}
{/if}
{/foreach}
{/if}
|
Ok ich habe das jetzt so gelöst, obwohl ich diese Methode ziemlich merkwürdig finde
Naja falls es doch eine andere Lösung geben sollte, wäre es nett wenn es mir wer posten würde.
danke |
|
Back to top |
|
coach Smarty Regular
Joined: 03 Jun 2004 Posts: 65
|
Posted: Thu Sep 23, 2004 4:18 pm Post subject: |
|
|
Hi,
ich glaube, ich hatte das gleiche Problem mal mit einem gelöst.
Coach[/quote] |
|
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
|