Last active
January 29, 2022 11:19
-
-
Save nobodyplace/6883821c7b39655e6ed7cf4f22897752 to your computer and use it in GitHub Desktop.
Smartyでファイルの更新日時を付与する動的プラグイン
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Index | |
{ | |
public function __construct() | |
{ | |
$smarty->registerPlugin('function', 'filemtime', array($this, 'smarty_function_filemtime')); | |
} | |
public function smarty_function_filemtime($params, $smarty) | |
{ | |
$file = $params['file']; | |
return $file.'?'.filemtime($_SERVER['DOCUMENT_ROOT'].$file); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<link rel="stylesheet" href="{filemtime file="/css/sample.css"}"> | |
→ /css/sample.css?1632201991 が出力される |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$smarty->registerPlugin('function', 'smarty_function_filemtime'); | |
function smarty_function_filemtime($params, $smarty) | |
{ | |
$file = $params['file']; | |
return $file.'?'.filemtime($_SERVER['DOCUMENT_ROOT'].$file); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment