Last active
September 27, 2017 10:59
-
-
Save syossan27/71f7a749b055930dade9 to your computer and use it in GitHub Desktop.
LaravelのBladeテンプレートを拡張する方法 ref: http://qiita.com/syossan27/items/94b7ec78a49c62379bbb
This file contains hidden or 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 | |
/* | |
* 現在日付の和暦を表示 | |
*/ | |
Blade::extend(function($view, $compiler) | |
{ | |
$pattern = $compiler->createMatcher('now_y'); | |
$now_year = date('Y'); | |
$japanese_calender_year = $now_year - 1988; | |
return preg_replace($pattern, '<?php echo date("'.$japanese_calender_year.'") ?>', $view); | |
}); | |
/* | |
* 現在日付の月を表示 | |
*/ | |
Blade::extend(function($view, $compiler) | |
{ | |
$pattern = $compiler->createMatcher('now_m'); | |
return preg_replace($pattern, '<?php echo date("n") ?>', $view); | |
}); | |
/* | |
* 現在日付の日を表示 | |
*/ | |
Blade::extend(function($view, $compiler) | |
{ | |
$pattern = $compiler->createMatcher('now_d'); | |
return preg_replace($pattern, '<?php echo date("j") ?>', $view); | |
}); |
This file contains hidden or 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 | |
/* | |
* 現在日付の和暦を表示 | |
*/ | |
Blade::extend(function($view, $compiler) | |
{ | |
$pattern = $compiler->createMatcher('now_y'); | |
$now_year = date('Y'); | |
$japanese_calender_year = $now_year - 1988; | |
return preg_replace($pattern, '<?php echo date("'.$japanese_calender_year.'") ?>', $view); | |
}); | |
/* | |
* 現在日付の月を表示 | |
*/ | |
Blade::extend(function($view, $compiler) | |
{ | |
$pattern = $compiler->createMatcher('now_m'); | |
return preg_replace($pattern, '<?php echo date("n") ?>', $view); | |
}); | |
/* | |
* 現在日付の日を表示 | |
*/ | |
Blade::extend(function($view, $compiler) | |
{ | |
$pattern = $compiler->createMatcher('now_d'); | |
return preg_replace($pattern, '<?php echo date("j") ?>', $view); | |
}); |
This file contains hidden or 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
Blade::extend(function($view, $compiler) | |
{ | |
$pattern = $compiler->createMatcher('拡張機能名'); | |
return preg_replace($pattern, '置き換えるPHPコード', $view); | |
}); |
This file contains hidden or 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
Blade::extend(function($view, $compiler) | |
{ | |
$pattern = $compiler->createMatcher('拡張機能名'); | |
return preg_replace($pattern, '置き換えるPHPコード', $view); | |
}); |
This file contains hidden or 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
require app_path().'/library/blade_extensions.php'; |
This file contains hidden or 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
require app_path().'/library/blade_extensions.php'; |
This file contains hidden or 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
@now_y() | |
@now_m() | |
@now_d() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment