Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [smarty] Wyświetlanie co drugiego wyniku w pętli
user123
post 11.06.2009, 22:38:59
Post #1





Grupa: Zarejestrowani
Postów: 231
Pomógł: 2
Dołączył: 2.08.2006
Skąd: Poznań

Ostrzeżenie: (10%)
X----


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.


--------------------
Youtube - Miedzynarodowa wersja: Wyposażenie siłowni
Go to the top of the page
+Quote Post
karolrynio
post 25.06.2009, 06:55:24
Post #2





Grupa: Zarejestrowani
Postów: 144
Pomógł: 25
Dołączył: 2.02.2009

Ostrzeżenie: (0%)
-----


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>
Go to the top of the page
+Quote Post
nmts
post 27.06.2009, 19:04:22
Post #3





Grupa: Zarejestrowani
Postów: 283
Pomógł: 34
Dołączył: 21.03.2008

Ostrzeżenie: (0%)
-----


  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}


--------------------
Free Web Tools - narzędzia dla programistów, webdeveloperów i specjalistów seo...
Go to the top of the page
+Quote Post
snakee
post 24.08.2012, 12:33:24
Post #4





Grupa: Zarejestrowani
Postów: 13
Pomógł: 0
Dołączył: 18.08.2012

Ostrzeżenie: (0%)
-----


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
Go to the top of the page
+Quote Post
nospor
post 24.08.2012, 14:57:43
Post #5





Grupa: Moderatorzy
Postów: 36 455
Pomógł: 6292
Dołączył: 27.12.2004




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...


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 24.04.2024 - 23:09