Kārlis Millers
Kārlis Millers

Reputation: 674

Add week in smarty tpl

I curently have {$order[orders].invoice_date|date_format:"%d.%m.%Y"}
But how to add week + 1?

So, I need to add 1 week and then formating this.
But the date isn't in the timestap format.

Smarty version: 3.1.
I can use only smarty logic, not PHP.

How to achieve this?

Upvotes: 1

Views: 1034

Answers (3)

Allan Nienhuis
Allan Nienhuis

Reputation: 4121

You shouldn't be doing this logic in smarty at all. This type of thing should be done in the php code - assign two date values to two separate smarty variables (one with the 1 week added), and use the appropriate one in the appropriate place in your template (applying the appropriate date_format as required).

edit: I know you've said you want to do this using smarty syntax - I'm just pointing out that trying to do this type of manipulation in smarty is not what the template language is designed for. If you only have access to the smarty .tpl files, you might try using the {php} tag to put your php logic in the .tpl file.

Upvotes: 0

Bjoern
Bjoern

Reputation: 16304

You don't need a plugin to work this out. It can be solved with a combination of cat and date_format.

Since date_format is a wrapper to PHPs strftime(), you can use the conversion specifiers available in strftime() - and that is what I used tackle the issue at hand.

Try this:

{$order[orders].invoice_date|cat:' +1 week'|date_format:"%d.%m.%Y"}

I've used Smarty version 3.1.17 to recreate your problem. The solution is based on the assumption that the value in your variable $order[orders].invoice_date is a string 2015-01-20 03:52:19.

Upvotes: 2

Mihai P.
Mihai P.

Reputation: 9357

You can create a smarty plugin, something like this one to suit your needs. http://smarty.incutio.com/?page=AlternativeDateModifierPlugin

Upvotes: 0

Related Questions