TP Underground Lounge 07/08
-


Hinweise


Antwort
 
LinkBack Themen-Optionen Thema durchsuchen Thema bewerten
Alt 18.06.2004, 11:07   #1
TP-Member
 
Benutzerbild von Eistee
 
Registriert seit: Dec 2003
Ort: Menden
Eistee macht alles soweit korrekt
Exclamation

Problem mit Smarty - Anfänger braucht Hilfe


Hallo, ich probiere mich grad darin, meine Seite auf smarty umzustricken.
Mitlerweile kan ich auch schon erste Erfolge verzeichnen
Allerdings macht mir ein News-Syste noch immer größere Probleme.
Zunächst mal der Code meiner index.php:

PHP-Code:
<?php
define
('SMARTY_DIR''/is/htdocs/47449/www.alkbrueder.de/smarty_alkbrueder/smarty/');

require(
SMARTY_DIR.'Smarty.class.php');

$tpl_ct = new smarty();
$tpl = new smarty();

include(
'thwbnews.php');
newstpl($tpl_ct);
$tpl->assign_by_ref('ct'$tpl_ct->fetch('templates/newsrow.html')); 

$tpl->display('templates/index.html');
?>
Nun ein Code-Ausschnitt aus der thwbnews.php, wie ich ihn bisher verändert habe:

PHP-Code:
while( list(, $thread) = each($a_thread) )
{
    if( 
$maxchars && strlen($thread['posttext']) > $maxchars )
    {
        
$newtext substr($thread['posttext'], 0$maxchars);
        for( 
$i $maxchars$i strlen($thread['posttext']); $i++ )
        {
            if( 
$thread['posttext'][$i] == ' ' || $thread['posttext'][$i] == "\n" )
                break;
            
$newtext .= $thread['posttext'][$i];            
        }
        
$more '<a href="'.$thwbpath.'showtopic.php?threadid='.$thread['threadid'].'"><img src="templates/images/for.gif" border="0" align="right"></a>';
        
$thread['posttext'] = $newtext;
    }
    else
    {
        
$more '<a href="'.$thwbpath.'showtopic.php?threadid='.$thread['threadid'].'"><img src="templates/images/for.gif" border="0" align="right"></a>';
    }

    
$tpl_ct->assign('topic'parse_code($thread['threadtopic']));
    
$tpl_ct->assign('date'date($date_format$thread['threadcreationtime']));
    
$tpl_ct->assign('author'$thread['threadauthor']);
    
$tpl_ct->assign('more'$more);
    
$tpl_ct->assign('text'parse_code($thread['posttext'], 1111));

Nun der selbe Teil, wie er im Original aussieht:

PHP-Code:
$tpl_newsrow file_get_contents("content/newsrow.html");

...

$news_output '';
while( list(, 
$thread) = each($a_thread) )
{
    if( 
$maxchars && strlen($thread['posttext']) > $maxchars )
    {
        
$newtext substr($thread['posttext'], 0$maxchars);
        for( 
$i $maxchars$i strlen($thread['posttext']); $i++ )
        {
            if( 
$thread['posttext'][$i] == ' ' || $thread['posttext'][$i] == "\n" )
                break;
            
$newtext .= $thread['posttext'][$i];            
        }
        
$more '<a href="'.$thwbpath.'showtopic.php?threadid='.$thread['threadid'].'"><img src="images/for.gif" border="0" align="right"></a>';
        
$thread['posttext'] = $newtext;
    }
    else
    {
        
$more '<a href="'.$thwbpath.'showtopic.php?threadid='.$thread['threadid'].'"><img src="images/for.gif" border="0" align="right"></a>';
    }

    
$row $tpl_newsrow;
    
$row str_replace('{more}'$more$row);
    
$row str_replace('{topic}'parse_code($thread['threadtopic']), $row);
    
$row str_replace('{text}'parse_code($thread['posttext'], 1111), $row);
    
$row str_replace('{author}'$thread['threadauthor'], $row);
    
$row str_replace('{date}'date($date_format$thread['threadcreationtime']), $row);
    
$row str_replace('{threadid}'$thread['threadid'], $row);
    
$row str_replace('{commentcount}'$thread['threadreplies'], $row);

    
    
$news_output .= $row;
}

...

print 
$news_output
Bei meiner abgeänderten Version besteht der Fehler darin, dass nur ein Eintrag aus DB gelesen und später ausgegeben wird. Das liegt daran, dass ich, nicht wie im Original, alle Einträge zunächst in der Variable $news_output speichern und später ausgeben kann.
Wie ist es dennoch möglich, alle Einträge per smarty auszugeben?
Wäre nett, wen ihr mir einen Lösungsweg konkret an diesem Beispiel erklären könntet, da ich mich erst seit wenigen Tagen überhaupt mit dieser Template-Engine beschäftige.
Danke!
Eistee ist offline   Mit Zitat antworten


Alt 18.06.2004, 21:51   #2
TP-Veteran
 
Benutzerbild von jonemo
 
Registriert seit: Dec 2002
Ort: london
jonemo macht sich hier sehr viel Mühe
Wenn ich dich richtig verstanden habe, hilft dir das.
__________________
the daily london photo
jonemo ist offline   Mit Zitat antworten
Alt 19.06.2004, 09:58   #3
TP-Member
 
Benutzerbild von Eistee
 
Registriert seit: Dec 2003
Ort: Menden
Eistee macht alles soweit korrekt
Könntest du mir auch erklären, wie ich das in meinem Fall zu verwenden habe?
Wäre nett.
Eistee ist offline   Mit Zitat antworten
Alt 19.06.2004, 11:30   #4
TP-Insider
 
Benutzerbild von loki
 
Registriert seit: May 2003
Ort: Aachen
loki ist auf einem guten Weg
PHP-Code:
$var = array();
while( list(, 
$thread) = each($a_thread) ) 

    if( 
$maxchars && strlen($thread['posttext']) > $maxchars 
    { 
        
$newtext substr($thread['posttext'], 0$maxchars); 
        for( 
$i $maxchars$i strlen($thread['posttext']); $i++ ) 
        { 
            if( 
$thread['posttext'][$i] == ' ' || $thread['posttext'][$i] == "\n" 
                break; 
            
$newtext .= $thread['posttext'][$i];             
        } 
        
$more '<a href="'.$thwbpath.'showtopic.php?threadid='.$thread['threadid'].'"><img src="templates/images/for.gif" border="0" align="right"></a>'
        
$thread['posttext'] = $newtext
    } 
    else 
    { 
        
$more '<a href="'.$thwbpath.'showtopic.php?threadid='.$thread['threadid'].'"><img src="templates/images/for.gif" border="0" align="right"></a>'
    } 
        
        
$threadtopic parse_code($thread['threadtopic']);
        
$date date($date_format$thread['threadcreationtime']);
        
$text parse_code($thread['posttext'], 1111);
        
        
$tmp = array(
            
'topic'=>$threadtopic,
            
'date'=>$date,
            
'author'=>$thread['threadauthor'],
            
'more',$more,
            
'text',$text
        
);
        
$var[] = $tmp;
        
        

  
   
    
$tpl_ct->assign('var'$var); 
Und das kannste dann so im tpl ausgeben:
HTML-Code:
{section name="nr" loop="$var"}
{$var[nr].text}
{sectionelse} 
Kein Text
{/section}
__________________
"Man muss die Welt nicht verstehen, man muss sich nur darin zurechtfinden."
Einstein

loki ist offline   Mit Zitat antworten
Alt 20.06.2004, 19:02   #5
TP-Member
 
Benutzerbild von Eistee
 
Registriert seit: Dec 2003
Ort: Menden
Eistee macht alles soweit korrekt
Danke für deine Hilfe, läuft jetzt bestens

Geändert von Eistee (20.06.2004 um 19:26 Uhr).
Eistee ist offline   Mit Zitat antworten
Antwort

  Aktuelles Thema
  TP Hilfe Forum > Web-Editoren & Coding > Traum-Dynamik
Problem mit Smarty - Anfänger braucht Hilfe Problem mit Smarty - Anfänger braucht Hilfe
« Ich möchte PHP lernen! | MySQL funktioniert nicht »

Aktive Benutzer in diesem Thema: 1 (Registrierte Benutzer: 0, Gäste: 1)
 
Themen-Optionen Thema durchsuchen
Thema durchsuchen:

Erweiterte Suche
Thema bewerten
Thema bewerten:

Forumregeln
Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are an
Gehe zu

Ähnliche Themen
Thema Autor Forum Antworten Letzter Beitrag
Neuling braucht Hilfe Jule Dreamweaver 5 21.03.2004 22:10
Problem mit Hintergrundfarbe asdf HTML Puristen 8 18.03.2004 11:10
Problem mit Cookies Flow09 Traum-Dynamik 9 19.02.2003 12:50
Verschiedene Problem mit GL 5.0 und NS 6.2 Karl GoLive 2 02.04.2002 22:18
Problem mit Segmente (HILFE........) Chris234 Fireworks 2 10.03.2002 14:08


Alle Zeitangaben in WEZ +2. Es ist jetzt 10:44 Uhr.

Powered by: vBulletin Version 3.7 (Deutsch)
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd. / Search Engine Friendly URLs by vBSEO 3.2.0 ©2008, Crawlability, Inc.
Traum-Projekt.com | Suchen | Archiv | Impressum | Kontakt | | | Nach oben |



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67