Skip to content

Commit 579e01c

Browse files
authored
Merge pull request #2 from librarianphp/custom-index-tpl
Adding config option for custom index tpl
2 parents 470cd0b + 070f6e4 commit 579e01c

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

Command/Web/IndexController.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ public function handle()
1919
$request = $this->getRequest();
2020

2121
if ($this->getApp()->config->site_index !== null) {
22+
$indexTpl = $this->getApp()->config->site_index_tpl ?? 'content/single.html.twig';
2223
$content = $content_provider->fetch($this->getApp()->config->site_index);
2324
if ($content) {
24-
$response = new Response($twig->render('content/single.html.twig', [
25+
$response = new Response($twig->render($indexTpl, [
2526
'content' => $content
2627
]));
2728

tests/Feature/CommandTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
$app->runCommand(['minicli', 'web', 'index']);
66
})->expectOutputRegex("/template listing/");
77

8+
test('Custom Index page is correctly loaded', function () {
9+
$app = getLibrarianIndex("posts/test0");
10+
$app->runCommand(['minicli', 'web', 'index']);
11+
})->expectOutputRegex("/custom index/");
812

913
test('Content page posts/test0 is correctly loaded', function () {
1014
$app = getLibrarianContent('test0');

tests/Pest.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,24 @@
4747
|
4848
*/
4949

50-
function getLibrarianIndex(): App
50+
function getLibrarianIndex(string $custom = null): App
5151
{
52-
$app = new App([
52+
$config = [
5353
'app_path' => [
5454
__DIR__ . '/../Command'
5555
],
5656
'data_path' => __DIR__ . '/Resources/data',
5757
'cache_path' => __DIR__ . '/Resources/cache',
5858
'templates_path' => __DIR__ . '/Resources/templates',
5959
'debug' => true
60-
]);
60+
];
61+
62+
if ($custom) {
63+
$config['site_index'] = $custom;
64+
$config['site_index_tpl'] = "content/custom_index.html.twig";
65+
}
6166

67+
$app = new App($config);
6268
$router = Mockery::mock(RouterServiceProvider::class);
6369
$request = Mockery::mock(Request::class);
6470
$request->shouldReceive('getParams');
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
custom index

0 commit comments

Comments
 (0)