1
tatane
Create a time function
  • 2013/8/23 10:09

  • tatane

  • Just can't stay away

  • Posts: 649

  • Since: 2008/5/6 1


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

2
Mamba
Re: Create a time function
  • 2013/8/23 10:36

  • Mamba

  • Moderator

  • Posts: 11409

  • Since: 2004/4/23


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.11 | Docs | Modules | Bugs

3
tatane
Re: Create a time function
  • 2013/8/23 10:39

  • tatane

  • Just can't stay away

  • Posts: 649

  • Since: 2008/5/6 1


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

4
Mamba
Re: Create a time function
  • 2013/8/23 10:58

  • Mamba

  • Moderator

  • Posts: 11409

  • Since: 2004/4/23


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.11 | Docs | Modules | Bugs

5
tatane
Re: Create a time function
  • 2013/8/23 11:58

  • tatane

  • Just can't stay away

  • Posts: 649

  • Since: 2008/5/6 1


Ok someone could help me create this code?

6
redheadedrod
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

7
Mamba
Re: Create a time function
  • 2013/8/23 18:40

  • Mamba

  • Moderator

  • Posts: 11409

  • Since: 2004/4/23


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.11 | Docs | Modules | Bugs

8
tatane
Re: Create a time function
  • 2013/8/24 7:10

  • tatane

  • Just can't stay away

  • Posts: 649

  • Since: 2008/5/6 1


a friend created this code
('Europe/Paris');  $onestle1 time(); $onestle $onestle1 7200# echo $onestle; $date1 = strtotime('23-08-2013'); $date2 = strtotime('24-08-2013'); # echo "
$date1
$date2
"; 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

9
Mamba
Re: Create a time function
  • 2013/8/24 7:54

  • Mamba

  • Moderator

  • Posts: 11409

  • Since: 2004/4/23


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.11 | Docs | Modules | Bugs

10
tatane
Re: Create a time function
  • 2013/8/24 8:02

  • tatane

  • Just can't stay away

  • Posts: 649

  • Since: 2008/5/6 1


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

Login

Who's Online

364 user(s) are online (226 user(s) are browsing Support Forums)


Members: 0


Guests: 364


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits