xoops forums

tatane

Just can't stay away
Posted on: 2013/8/23 10:09
tatane
tatane (Show more)
Just can't stay away
Posts: 649
Since: 2008/5/6 1
#1

Create a time function

Hello
Can we create a time with smarty function? For example, I would make a visible link from September 1 to September 25.

thank you

Mamba

Moderator
Posted on: 2013/8/23 10:36
Mamba
Mamba (Show more)
Moderator
Posts: 10792
Since: 2004/4/23
#2

Re: Create a time function

I think, Smarty should be only used for "Presentation". The logic should be done in PHP.

So if you want to show a link only at a given time, then you should calculate it in PHP and assign the variable only if the time is correct.
Support XOOPS => DONATE
Use 2.5.10 | Docs | Modules | Bugs

tatane

Just can't stay away
Posted on: 2013/8/23 10:39
tatane
tatane (Show more)
Just can't stay away
Posts: 649
Since: 2008/5/6 1
#3

Re: Create a time function

Ok and can not from {$smarty.now} ?

Mamba

Moderator
Posted on: 2013/8/23 10:58
Mamba
Mamba (Show more)
Moderator
Posts: 10792
Since: 2004/4/23
#4

Re: Create a time function

This will give you the time "now" to display it.

But again - you should fight the temptation to do calculations in Smarty. The whole purpose of Smarty (as a "presentation layer") is to "present" what the "business layer" is sending.

So it's best to have a clear separation between them:

- we should not have any HTML code in PHP files
- we should not do any calculations in the Smarty templates
Support XOOPS => DONATE
Use 2.5.10 | Docs | Modules | Bugs

tatane

Just can't stay away
Posted on: 2013/8/23 11:58
tatane
tatane (Show more)
Just can't stay away
Posts: 649
Since: 2008/5/6 1
#5

Re: Create a time function

Ok someone could help me create this code?

redheadedrod

Home away from home
Posted on: 2013/8/23 17:49
redheadedrod
redheadedrod (Show more)
Home away from home
Posts: 1296
Since: 2008/2/26
#6

Re: Create a time function

Mamba is correct, you want to have as little coding in your templates as possible.

If you look at templates for your module there should be a PHP portion and a smarty template section.

You setup a series of variables that get passed to smarty and smarty will take it from there and build your display from the template. The logic in Smarty should be very simple and only reference those variables passed to it.

All of the setting up of that variable should be done in your php code and then gets passed to smarty.

Examples of this can be found in just about any major module that uses smarty to build a display.

I did look for a quick and dirty sample but I am not currently coding anything with smarty or templates and it was last year since I have done this so it is a little hard to remember the exact syntax. Plus it will depend on how your module is doing it.

If you are wanting to do this in a theme you will have to add code to the themes PHP file that loads the html files. You will want to make sure the smarty variables are setup before you display any HTML files.

Hopefully this can head you in the right direction. It is very difficult for me to otherwise help you when I don't know what you have that you are starting from or if you are doing this in a theme so it is site wide or just in a module.

Rodney

Mamba

Moderator
Posted on: 2013/8/23 18:40
Mamba
Mamba (Show more)
Moderator
Posts: 10792
Since: 2004/4/23
#7

Re: Create a time function

Quote:
Ok someone could help me create this code?

Tatane, you can take a look at this for checking if the date is between two dates.

If it is, you can then assign a Smarty variable, and then use it in your theme.
Support XOOPS => DONATE
Use 2.5.10 | Docs | Modules | Bugs

tatane

Just can't stay away
Posted on: 2013/8/24 7:10
tatane
tatane (Show more)
Just can't stay away
Posts: 649
Since: 2008/5/6 1
#8

Re: Create a time function

a friend created this code
<?php date_default_timezone_set('Europe/Paris');  $onestle1 time(); $onestle $onestle1 7200# echo $onestle; $date1 = strtotime('23-08-2013'); $date2 = strtotime('24-08-2013'); # echo "<br>$date1<br>$date2<br>"; if ( $date1 <= $onestle OR $date2 <= $onestle ) {  ?> my link <? ?>


it runs on a php page but I do not know where to put it to work in my theme.html because php is not recommended in theme.html

Mamba

Moderator
Posted on: 2013/8/24 7:54
Mamba
Mamba (Show more)
Moderator
Posts: 10792
Since: 2004/4/23
#9

Re: Create a time function

What are you trying to do? When should the link be visible and why?

It always helps when people explain what they actually are trying to accomplish as an end result.
Support XOOPS => DONATE
Use 2.5.10 | Docs | Modules | Bugs

tatane

Just can't stay away
Posted on: 2013/8/24 8:02
tatane
tatane (Show more)
Just can't stay away
Posts: 649
Since: 2008/5/6 1
#10

Re: Create a time function

As I explained in my first post, I want to make visible a link from September 1 to September 31.

I would put this link in my theme.html so I have to create a smarty.

I thought to my php code in a custom block, but it does not work