Skip to content

Instantly share code, notes, and snippets.

@nobodyplace
Last active January 29, 2022 11:19
Show Gist options
  • Save nobodyplace/6883821c7b39655e6ed7cf4f22897752 to your computer and use it in GitHub Desktop.
Save nobodyplace/6883821c7b39655e6ed7cf4f22897752 to your computer and use it in GitHub Desktop.
Smartyでファイルの更新日時を付与する動的プラグイン
<?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);
}
}
<link rel="stylesheet" href="{filemtime file="/css/sample.css"}">
→ /css/sample.css?1632201991 が出力される
<?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