diff --git a/src/lib/Sage/Template/BladeProvider.php b/src/lib/Sage/Template/BladeProvider.php index 0c7bd0d..9fa89d2 100644 --- a/src/lib/Sage/Template/BladeProvider.php +++ b/src/lib/Sage/Template/BladeProvider.php @@ -4,6 +4,7 @@ namespace Roots\Sage\Template; use Jenssegers\Blade\Blade; use Illuminate\View\Engines\CompilerEngine; +use Illuminate\Contracts\Container\Container as ContainerContract; class BladeProvider extends Blade { @@ -13,6 +14,19 @@ class BladeProvider extends Blade /** @var string */ protected $cachePath; + /** + * Constructor. + * + * @param array $viewPaths + * @param string $cachePath + * @param ContainerContract $container + */ + public function __construct($viewPaths, $cachePath, ContainerContract $container = null) + { + parent::__construct($viewPaths, $cachePath, $container); + $this->registerViewFinder(); + } + /** * @param string $view * @param array $data @@ -59,6 +73,20 @@ class BladeProvider extends Blade return $compiledPath; } + /** + * Register the view finder implementation. + * + * @return void + */ + public function registerViewFinder() + { + $this->container->bind('view.finder', function ($app) { + $paths = $app['config']['view.paths']; + + return new FileViewFinder($app['files'], $paths); + }); + } + /** * @param string $file * @return string diff --git a/src/lib/Sage/Template/FileViewFinder.php b/src/lib/Sage/Template/FileViewFinder.php new file mode 100644 index 0000000..9cade3f --- /dev/null +++ b/src/lib/Sage/Template/FileViewFinder.php @@ -0,0 +1,30 @@ +possible_parts_delimiter, $name); + $templates[] = array_shift($parts); + foreach ($parts as $i => $part) { + $templates[] = $templates[$i].$this->possible_parts_delimiter.$part; + } + rsort($templates); + return call_user_func_array('array_merge', array_map(function ($template) { + return array_map(function ($extension) use ($template) { + return str_replace('.', '/', $template).'.'.$extension; + }, $this->extensions); + }, $templates)); + } +} diff --git a/templates/index.blade.php b/templates/index.blade.php index cc334fb..869ed6f 100644 --- a/templates/index.blade.php +++ b/templates/index.blade.php @@ -11,7 +11,7 @@ @endif @while (have_posts()) @php the_post() @endphp - @include ('partials.content') + @include ('partials.content-'.(get_post_type() !== 'post' ? get_post_type() : get_post_format())) @endwhile {!! get_the_posts_navigation() !!} diff --git a/templates/single.blade.php b/templates/single.blade.php index bfe1890..a383216 100644 --- a/templates/single.blade.php +++ b/templates/single.blade.php @@ -2,7 +2,7 @@ @section('content') @while(have_posts()) @php the_post() @endphp - @include('partials/content-single') + @include('partials/content-single-'.get_post_type()) @endwhile @endsection