LISE template / or general question Topic is solved

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
smithdesign77
Forum Members
Forum Members
Posts: 25
Joined: Mon Jan 02, 2017 10:27 pm

LISE template / or general question

Post by smithdesign77 »

Hi!
I do have a working solution - but I wonder, if this could have been accomplished quicker/shorter in code.
I wanted to write a "last updated on" (German date, which is bad to sort by) at the very end of the LISE items.
This is what I have so far and what does work:

Code: Select all

<p><small>Last updated: {foreach from=$items item=item}
  {if !isset($highdate)}{assign highdate value=$item->modified_time|date_format:'%Y%m%d'}{/if}
  {if ($item->modified_time|date_format:'%Y%m%d' > $highdate)}{assign highdate value=$item->modified_time|date_format:'%Y%m%d'}{/if}
  {if $item@last}{$highdate|substr:-2}.{$highdate|substr:-4|truncate:2:''}.{$highdate|substr:-8|truncate:4:''}{/if}
{/foreach}</small></p>
If I only wrote {$highdate|date_format:'%d.%m.%Y'} the contents was wrong and the date was something in 1970. Hence all the substr and truncates.
I'd be glad to learn something - if you had the time to answer I'd appreciate it; again, this solution does the trick, so no biggie. ^-^
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3484
Joined: Mon Nov 28, 2011 9:29 am
Location: The Netherlands

Re: LISE template / or general question

Post by velden »

I'd expect the modified_time can already be compared without coverting it to a string.
Converting it to a string probably is the reason why you can't use {$highdate|date_format:'%d.%m.%Y'}
I wanted to write a "last updated on" (German date, which is bad to sort by) at the very end of the LISE items.
If you're already displaying (hence iterating) the items before, I'd include your logic inside that loop.
Once the loop is finished, you can just display the highdate.

The same applies to your loop (untested):

Code: Select all

{foreach from=$items item=item}
  {if !isset($highdate)}{assign highdate value=$item->modified_time|date_format:'%Y%m%d'}{/if}
  {if ($item->modified_time|date_format:'%Y%m%d' > $highdate)}{assign highdate value=$item->modified_time|date_format:'%Y%m%d'}{/if}
{/foreach}
<p><small>Last updated: {$highdate|substr:-2}.{$highdate|substr:-4|truncate:2:''}.{$highdate|substr:-8|truncate:4:''}</small></p>
smithdesign77
Forum Members
Forum Members
Posts: 25
Joined: Mon Jan 02, 2017 10:27 pm

Re: LISE template / or general question

Post by smithdesign77 »

Yup, you nailed it! ;D
My new code is now:

Code: Select all

{foreach original loop - no extra looping now…
{if !isset($highdate)}{assign highdate value=$item->modified_time}{/if}
{if ($item->modified_time > $highdate)}{assign highdate value=$item->modified_time}{/if}
{/foreach}
and then later only the variable {$highdate|date_format:'%d.%m.%Y'} — outputted with the correct format, without any substr, etc.
Awesome! THANKS!
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3484
Joined: Mon Nov 28, 2011 9:29 am
Location: The Netherlands

Re: LISE template / or general question

Post by velden »

Cool

Maybe you could even move the initial assign outside the loop (again untested):

Code: Select all

{$highdate=0}
{foreach original loop - no extra looping now…
{if ($item->modified_time > $highdate)}{assign highdate value=$item->modified_time}{/if}
{/foreach}
Post Reply

Return to “Modules/Add-Ons”