Skip to content

Commit

Permalink
Merge pull request #2 from librarianphp/custom-index-tpl
Browse files Browse the repository at this point in the history
Adding config option for custom index tpl
  • Loading branch information
erikaheidi authored May 7, 2023
2 parents 470cd0b + 070f6e4 commit 579e01c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
3 changes: 2 additions & 1 deletion Command/Web/IndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ public function handle()
$request = $this->getRequest();

if ($this->getApp()->config->site_index !== null) {
$indexTpl = $this->getApp()->config->site_index_tpl ?? 'content/single.html.twig';
$content = $content_provider->fetch($this->getApp()->config->site_index);
if ($content) {
$response = new Response($twig->render('content/single.html.twig', [
$response = new Response($twig->render($indexTpl, [
'content' => $content
]));

Expand Down
4 changes: 4 additions & 0 deletions tests/Feature/CommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
$app->runCommand(['minicli', 'web', 'index']);
})->expectOutputRegex("/template listing/");

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

test('Content page posts/test0 is correctly loaded', function () {
$app = getLibrarianContent('test0');
Expand Down
12 changes: 9 additions & 3 deletions tests/Pest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,24 @@
|
*/

function getLibrarianIndex(): App
function getLibrarianIndex(string $custom = null): App
{
$app = new App([
$config = [
'app_path' => [
__DIR__ . '/../Command'
],
'data_path' => __DIR__ . '/Resources/data',
'cache_path' => __DIR__ . '/Resources/cache',
'templates_path' => __DIR__ . '/Resources/templates',
'debug' => true
]);
];

if ($custom) {
$config['site_index'] = $custom;
$config['site_index_tpl'] = "content/custom_index.html.twig";
}

$app = new App($config);
$router = Mockery::mock(RouterServiceProvider::class);
$request = Mockery::mock(Request::class);
$request->shouldReceive('getParams');
Expand Down
1 change: 1 addition & 0 deletions tests/Resources/templates/content/custom_index.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
custom index

0 comments on commit 579e01c

Please sign in to comment.