Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Template mit enthaltenen Template Blöcken

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Language: German
View previous topic :: View next topic  
Author Message
kid
Smarty Rookie


Joined: 04 Jul 2004
Posts: 13

PostPosted: Sun Jul 04, 2004 5:24 pm    Post subject: Template mit enthaltenen Template Blöcken Reply with quote

Hallo,

ich hab noch nicht so den Einstieg zu Smarty gefunden. Crying or Very sad

Ich hab eine Produktseite mit 20 Produkten. Jedes Produkt wird als ein Block dargestellt. Der Block soll ein eigenes Template haben. Wie realisiere ich das, ohne jedesmal die Seite neu generieren zu lassen?

Ich hab mal gelesen am besten mit einer Funktion in Smarty selber schreiben ?!? - Gibbet dazu irgendwo ein HowTo oder sowas?
Also die Problematik müsste ja oft auftreten.

Viele Grüße,

Alexander
Back to top
View user's profile Send private message AIM Address MSN Messenger
kills
Smarty Elite


Joined: 28 May 2004
Posts: 493

PostPosted: Mon Jul 05, 2004 1:27 pm    Post subject: Reply with quote

Hi Alexander,

schau mal hier:

http://smarty.php.net/manual/en/language.function.section.php

oder hier:

http://smarty.php.net/manual/en/language.function.foreach.php
Back to top
View user's profile Send private message
kid
Smarty Rookie


Joined: 04 Jul 2004
Posts: 13

PostPosted: Mon Jul 05, 2004 6:38 pm    Post subject: Reply with quote

Hallo,

ne, die Schleife mein ich nicht. jetzt müsste ein Block je ein Template sein.

Also mal Pseudocode mässig:
Code:

template Liste

solange i<20 zeige produkte an {
  template produkt
    zeige produkt(i)
  template produkt ende
  i++
}

template Liste ende


Die Problematik sind die geschachtelten Templates, nicht die Schleife.

Oder cacht der das so trotzdem richtig?
Back to top
View user's profile Send private message AIM Address MSN Messenger
kid
Smarty Rookie


Joined: 04 Jul 2004
Posts: 13

PostPosted: Mon Jul 05, 2004 6:40 pm    Post subject: Reply with quote

Also das Produkt sollte ein eigenes Template haben, weil das an vielen Stellen immer wieder so ausgegeben wird. Deshalb macht eine feste Programmierung in der Schleife in dem Fall keinen Sinn.
Back to top
View user's profile Send private message AIM Address MSN Messenger
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Mon Jul 05, 2004 7:39 pm    Post subject: Reply with quote

kid wrote:
Oder cacht der das so trotzdem richtig?


ja tut "er". Smile

Code:
{foreach from=$produkte item=produkt}{include file="produkt.tpl"}{/foreach}
(das gleiche template für verschiedene produkte)

oder

Code:
{foreach from=$produkte item=produkt}{include file=$produkt.template}{/foreach}
(verschiedene templates für verschiedene produkte)
Back to top
View user's profile Send private message Send e-mail Visit poster's website
coach
Smarty Regular


Joined: 03 Jun 2004
Posts: 65

PostPosted: Tue Jul 06, 2004 7:17 am    Post subject: Reply with quote

Moin,

Code:
{foreach from=$produkte key=produkt item=produkt_template}{include file=$produkt_template}{/foreach}

(du überweist also z.B. aus einer DB den Typ des Templates einem Produk zu)

Falls du nun aber z.B. jeden Block separat cachen möchtest, dann kommst du evtl. um ein Plugin (siehe ein paar Postings weiter meinen Artikel) nicht herum.

Alternativ könntest du die Schleife im PHP-Script machen und z.B. 20 mal testen, ob das Produkt[$i] im Cache ist, bei Bedarf aus der DB holen, dann fetch() und alle Produkte zusammenfügen. Dies z.B. wieder in einem "Master"-Template, der quasi aus einem Array einfach nur HTML-Schnipsel holt (diese hast du vorher im PHP-Sript per fetch() geholft und in ein Array gepackt).


Coach
Back to top
View user's profile Send private message
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Tue Jul 06, 2004 7:59 am    Post subject: Reply with quote

coach wrote:
Alternativ könntest du die Schleife im PHP-Script machen und z.B. 20 mal testen, ob das Produkt[$i] im Cache ist, bei Bedarf aus der DB holen, dann fetch() und alle Produkte zusammenfügen. Dies z.B. wieder in einem "Master"-Template, der quasi aus einem Array einfach nur HTML-Schnipsel holt (diese hast du vorher im PHP-Sript per fetch() geholft und in ein Array gepackt).


das klingt für mich unnötig kompliziert. bei 20 produkten würde ich die ganze seit cachen, fertig. wenn sich ein produkt ändert, wird der cache für diese seite gelöscht, fertig.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
kid
Smarty Rookie


Joined: 04 Jul 2004
Posts: 13

PostPosted: Thu Jul 08, 2004 9:35 am    Post subject: Reply with quote

Sauberst, danke für die Infos.

Dann werd ich das mal so angehen. Very Happy
Back to top
View user's profile Send private message AIM Address MSN Messenger
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Language: German All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP