Skip to content

Commit

Permalink
Merge pull request #1941 from kaisermann/fix-template-controller
Browse files Browse the repository at this point in the history
Ensure templates filenames without path and extension.
  • Loading branch information
retlehs authored Aug 17, 2017
2 parents e00eaf7 + 33b981c commit 499f809
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions app/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,25 @@ function asset_path($asset)
*/
function filter_templates($templates)
{
$paths = apply_filters('sage/filter_templates/paths', [
'views',
'resources/views'
]);
$paths_pattern = "#^(" . implode('|', $paths) . ")/#";

return collect($templates)
->map(function ($template) {
return preg_replace('#\.(blade\.)?php$#', '', ltrim($template));
->map(function ($template) use ($paths_pattern) {
/** Remove .blade.php/.blade/.php from template names */
$template = preg_replace('#\.(blade\.?)?(php)?$#', '', ltrim($template));

/** Remove partial $paths from the beginning of template names */
if (strpos($template, '/')) {
$template = preg_replace($paths_pattern, '', $template);
}

return $template;
})
->flatMap(function ($template) {
$paths = apply_filters('sage/filter_templates/paths', ['views', 'resources/views']);
->flatMap(function ($template) use ($paths) {
return collect($paths)
->flatMap(function ($path) use ($template) {
return [
Expand Down

0 comments on commit 499f809

Please sign in to comment.