Skip to content

Instantly share code, notes, and snippets.

@nobodyplace
Last active January 30, 2022 00:04
Show Gist options
  • Save nobodyplace/3549a40e4335eeb5388a94a868389c0d to your computer and use it in GitHub Desktop.
Save nobodyplace/3549a40e4335eeb5388a94a868389c0d to your computer and use it in GitHub Desktop.
Smartyでファイルの更新日時を付与する動的プラグイン
<?php
class DisplayManager
{
function __construct()
{
$this->_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);
}
}
<!--{filemtime file="/css/reset.css"}-->
→ /css/reset.css?1632201991 と出力される
@nobodyplace
Copy link
Author

制限事項:CSSを絶対パスで指定する必要がある

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment