Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [smarty] Wyświetlanie co drugiego wyniku w pętli
Forum PHP.pl > Forum > Gotowe rozwiązania > Systemy szablonów
user123
Witam,

w jakis sposób za pomocą pętli w smartach stworzyć dwie kolumny. Zademonstruje to na przykładzie:

  1. {foreach from=$cos item=bbb key=i}
  2. <tr>
  3. <td>{$questionmark.gifquestionmark.gif}</td>
  4. <td>{$questionmark.gifquestionmark.gif}</td>
  5. </tr>
  6. {/foreach}


w jakis sposób wywołać smarty aby stworzyć dwie kolumny róznych danych.
karolrynio
Możesz spróbować czegoś takiego:
Kod
<table>
{foreach from=$cos item=bbb key=i name="lalal"}
{if $smarty.foreach.lalal.iteration%2==1}
<tr>
{/if}
<td>{$??}</td>
{if $smarty.foreach.lalal.iteration%2==0 || $smarty.foreach.lalal.last}
</tr>
{/if}
{/foreach}
</table>
nmts
  1. {section name=nazwa loop=10}
  2. {if %nazwa.index% is not odd}
  3. <tr>
  4. {/if}
  5. <td></td>
  6. {if %nazwa.index% is odd}
  7. </tr>
  8. {/if}
  9. {/section}
snakee
Jestem początkującym w smarty i prosże o pomoc zwłaszcza jak kod z książki

http://helion.pl/ebooki/smarty-szablony-w-...marty_ebook.htm

którą kupiłem wyświetla bląd przy kompilowaniu:

Fatal error: Uncaught exception 'SmartyCompilerException' with message 'Syntax Error in template "./templates/index.tpl" on line 29 "{if %tabela.index% is not odd}" - Unexpected "%"' in /home/dealer/main/pkg/cherr/luki/html/smarty/libs/sysplugins/smarty_internal_templatecompilerbase.php:656 Stack trace: #0 /home/dealer/main/pkg/cherr/luki/html/smarty/libs/sysplugins/smarty_internal_templateparser.php(3139): Smarty_Internal_TemplateCompilerBase->trigger_template_error() #1 /home/dealer/main/pkg/cherr/luki/html/smarty/libs/sysplugins/smarty_internal_templateparser.php(3204): Smarty_Internal_Templateparser->yy_syntax_error(40, '%') #2 /home/dealer/main/pkg/cherr/luki/html/smarty/libs/sysplugins/smarty_internal_smartytemplatecompiler.php(105): Smarty_Internal_Templateparser->doParse(40, '%') #3 /home/dealer/main/pkg/cherr/luki/html/smarty/libs/sysplugins/smarty_internal_templatecompilerbase.php(192): Smarty_Internal_SmartyTemplateCompiler->doCompile('<html>??<head> ...') #4 /home/dealer/main/pkg/cherr/luki/html/smarty/libs/ in /home/dealer/main/pkg/cherr/luki/html/smarty/libs/sysplugins/smarty_internal_templatecompilerbase.php on line 656

jeśli wykasuję instrukcję {if %tabela.index% is not odd}
to działa jak należy

co tu jest nie tak questionmark.gif

[SMARTY] pobierz, plaintext
  1. <html>
  2. <head> <title> Przyk3ad architektury witryny </title>
  3. </head>
  4.  
  5. <body>
  6.  
  7. <table border="0" width="100%">
  8. <tr>
  9. <td align="left">
  10. <a href="http://www.packtpub.com">
  11. <img src="images\PacktLogoSmall.png" border="0">
  12. </a>
  13. <img src="images\focused.gif">
  14. </td>
  15. <td>
  16. <h1> Rozdzia3 2 — przyk3ad </h1>
  17. </td>
  18. </tr>
  19. </table>
  20.  
  21. <br>
  22. Oto ksi1żki wyœwietlane w tabeli sk3adaj1cej si蟺 dw��kolumn:
  23. <br> <br>
  24.  
  25. <table border="1" width="100%">
  26.  
  27. {section name=tabela loop=$book->title}
  28.  
  29. {if %tabela.index% is not odd}
  30.  
  31. <tr>
  32. {/if}
  33.  
  34. <td align="left">
  35. <table>
  36. <tr>
  37. <td>
  38. <img src="images\{$book->image[tbl]}" width="220">
  39. </td>
  40.  
  41. <td valign="top">
  42. <font size=+1><b> {$book->title[tbl]} </b></font><br>
  43. <font size=-1 color=blue><b> {$book->author[tbl]} </b></font><br>
  44. {$book->description[tbl]} <br>
  45. Rok wydania: {$book->year[tbl]} <br>
  46. <font size=-1>Cena: <s>{$book->price[tbl]}</s> PLN</font> <br>
  47. Nasza cena: {$book->discounted[tbl]} PLN
  48. <font color=red> oszcz飺aj {$book->discount[tbl]} % </font>
  49. </td>
  50. </tr>
  51. </table>
  52. </td>
  53.  
  54. {if %tabela.index% is odd}
  55.  
  56. </tr>
  57. {/if}
  58.  
  59.  
  60. </table>
  61.  
  62. </body>
  63.  
  64. </html>
[SMARTY] pobierz, plaintext
nospor
Cytat
jeśli wykasuję instrukcję {if %tabela.index% is not odd}
Można się więc domyślić, że nie ta konstrukcja nie jest używana w wersji smarty, którą ty masz...
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2024 Invision Power Services, Inc.