View previous topic :: View next topic |
Author |
Message |
micab Smarty Rookie
Joined: 29 May 2015 Posts: 6
|
Posted: Fri May 29, 2015 8:30 am Post subject: How to sort items by date & calendar week |
|
|
Hi smarty experts!
would highly appreciate if someone could kindly let me know how to sort and display items by date added & for each calendar week a new row.
-----------------------------------------
for eg:
items added for calendar week 20
a row with items for that week
items added for calendar week 19
a row with items for that week
items added for calendar week 18
a row with items for that week
etc..
-----------------------------------------
any ideas?
thanks in advance |
|
Back to top |
|
micab Smarty Rookie
Joined: 29 May 2015 Posts: 6
|
Posted: Tue Jun 02, 2015 10:47 am Post subject: |
|
|
i tried the following but with no success. can someone please help me out. thanks in advance.
{foreach item=table_data from=$products|@sortby:"-#date_added"}
<div class="{cycle values="odd"}">{$table_data.date_added|date_format:"%V"}</div>
{foreach from=$table_data.date_added|date_format:"%V" item=stat}
<div class="{cycle values="even"}">
{$stat}
{/foreach}
{/foreach}</div> |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Tue Jun 02, 2015 11:01 am Post subject: |
|
|
Do your sorting in your application code. Template code should only display them. |
|
Back to top |
|
micab Smarty Rookie
Joined: 29 May 2015 Posts: 6
|
Posted: Tue Jun 02, 2015 11:22 am Post subject: |
|
|
the issue that i´m having is to have it displayed in the right order. the result that i´m getting is:
Week 22
item 1 - Date added: 28.05.2015
Week 22
item 2 - Date added: 28.05.2015
Week 22
item 3 - Date added: 28.05.2015
Week 16
item 1 - Date added: 15.04.2015
Week 12
item 1 - Date added: 18.03.2015
Week 12
item 2 - Date added: 18.03.2015
etc.
but i wish to have it displayed as:
Week 22
item 1 - Date added: 28.05.2015
item 2 - Date added: 28.05.2015
item 3 - Date added: 28.05.2015
Week 16
item 1 - Date added: 15.04.2015
Week 12
item 1 - Date added: 18.03.2015
item 2 - Date added: 18.03.2015
|
|
Back to top |
|
adn Smarty Regular
Joined: 31 May 2011 Posts: 91
|
Posted: Tue Jun 02, 2015 2:19 pm Post subject: |
|
|
Hi micab,
I have this kind of thing in some tpl and I do something like that with only one loop. Not tested
Code: | {$week=''}
{foreach item=table_data from=$products|@sortby:"-#date_added"}
{if $week != $table_data.date_added|date_format:"%V"}
<div class="{cycle values="odd"}">{$table_data.date_added|date_format:"%V"}</div>
{$week=$table_data.date_added|date_format:"%V"}
{/if}
<div class="{cycle values="even"}">{$stat}</div>
{/foreach} |
_________________ http://www.letsGarden.info |
|
Back to top |
|
micab Smarty Rookie
Joined: 29 May 2015 Posts: 6
|
Posted: Tue Jun 02, 2015 3:07 pm Post subject: |
|
|
thanks adn, it doesn t seem to be working. |
|
Back to top |
|
adn Smarty Regular
Joined: 31 May 2011 Posts: 91
|
|
Back to top |
|
micab Smarty Rookie
Joined: 29 May 2015 Posts: 6
|
Posted: Tue Jun 02, 2015 3:48 pm Post subject: |
|
|
no output, just a blank page. |
|
Back to top |
|
adn Smarty Regular
Joined: 31 May 2011 Posts: 91
|
Posted: Wed Jun 03, 2015 6:52 am Post subject: |
|
|
At least one mistake in my code on $stat
{$week=''}
{foreach item=table_data from=$products|@sortby:"-#date_added"}
{if $week != $table_data.date_added|date_format:"%V"}
<div class="{cycle values="odd"}">{$table_data.date_added|date_format:"%V"}</div>
{$week=$table_data.date_added|date_format:"%V"}
{/if}
<div class="{cycle values="even"}">{$table_data.date_added}</div>
{/foreach} _________________ http://www.letsGarden.info |
|
Back to top |
|
micab Smarty Rookie
Joined: 29 May 2015 Posts: 6
|
Posted: Wed Jun 03, 2015 7:00 am Post subject: |
|
|
Hi adn, still the same error - no output just a blank page |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Wed Jun 03, 2015 9:00 am Post subject: |
|
|
Enable all error reporting. |
|
Back to top |
|
|