Announcement

  •  » Themes
  •  » Add date php to a theme .tpl file

#1 2023-01-28 11:00:02

AHs
Member
2023-01-28
4

Add date php to a theme .tpl file

Hello/Hi/Greetings,

I'm trying to add date php to a .tpl file.
I understand I can add
$smarty->assign('currentDate', $date("Y-m-d")); to a php file.
and then
<h1>{$currentDate}</h1>
to the .tpl file.
Which php file should I add the $smarty tag to?
Many thanks.





(Copy here your environment details, found on your Piwigo page [Administration > Tools > Maintenance])

Piwigo URL: http://

Offline

 

#2 2023-01-28 13:13:27

ddtddt
Piwigo Team
Quetigny - France
2007-07-27
7208

Re: Add date php to a theme .tpl file

Hi :-)

Where ?

photo page ? header? footer ?


You love Piwigo so don't hesitate to participate, learn more on the "Contribute to Piwigo" page. If you don't have much time for contribution, you can also help the project with a donation.

Offline

 

#3 2023-01-28 14:03:40

AHs
Member
2023-01-28
4

Re: Add date php to a theme .tpl file

Hi,
It's the footer.tpl on the Bootstrap Darkroom theme.
Line 15 - I would like to insert a &copy; php current year tag, so it's
{'Powered by'|@translate}    <a href="{$PHPWG_URL}" class="Piwigo">Piwigo</a> | &copy;{php current year tag}  AH Photos
Thanks.

Offline

 

#4 2023-01-28 14:30:39

ddtddt
Piwigo Team
Quetigny - France
2007-07-27
7208

Re: Add date php to a theme .tpl file

Personal plugin

add_event_handler('loc_end_page_tail', 'datefooter');
function datefooter(){
        global $template;
       $template->assign('currentDate', date("Y-m-d"));

    $template->append('footer_elements', '<h1>{$currentDate}</h1>');
  }
}


You love Piwigo so don't hesitate to participate, learn more on the "Contribute to Piwigo" page. If you don't have much time for contribution, you can also help the project with a donation.

Offline

 

#5 2023-01-28 15:40:15

AHs
Member
2023-01-28
4

Re: Add date php to a theme .tpl file

Hi,
I made this plugin and loaded into the plugins folder.

<?php
/*
Plugin Name: Date Code
Version: 1.0
*/

add_event_handler('loc_end_page_tail', 'datefooter');
function datefooter()
{

    $template->assign('currentDate', $date("Y-m-d"));
    $template->append('footer_elements', '<h1>{$currentDate}</h1>');
}

?>

I had to remove the last brace from the code you sent but I now get this error,
"Notice: Undefined variable: template in /home/ahimage/public_html/pm/plugins/Datetag/main.inc.php on line 10"

To see the full error message go to: https://www.ahimages.co.uk/pm/

Thanks
AH

Offline

 

#6 2023-01-29 07:31:24

ddtddt
Piwigo Team
Quetigny - France
2007-07-27
7208

Re: Add date php to a theme .tpl file

Hi :-)

create file footerdate.tpl in personal plugin

Code:

<h1>{$currentDate}</h1>

and in main.inc.php

Code:

define('Pdate_DIR' , basename(dirname(__FILE__)));
define('Pdate_PATH' , PHPWG_PLUGINS_PATH . Pdate_DIR . '/');

add_event_handler('loc_end_page_tail', 'datefooter');
function datefooter()
{
  global $template;
  
    $template->assign('currentDate', date("Y-m-d"));
    $template->set_filename('footerdate', realpath(Pdate_PATH.'footerdate.tpl'));  
    $template->append('footer_elements', $template->parse('footerdate', true));
}

You love Piwigo so don't hesitate to participate, learn more on the "Contribute to Piwigo" page. If you don't have much time for contribution, you can also help the project with a donation.

Offline

 

#7 2023-01-29 09:45:41

AHs
Member
2023-01-28
4

Re: Add date php to a theme .tpl file

That's working. Many thanks for the help.  :)

Offline

 
  •  » Themes
  •  » Add date php to a theme .tpl file

Board footer

Powered by FluxBB

github twitter newsletter Donate Piwigo.org © 2002-2024 · Contact