Skip to content

Commit 59002e1

Browse files
committed
getEnv default value, configurable page regions
1 parent be49fba commit 59002e1

File tree

4 files changed

+38
-38
lines changed

4 files changed

+38
-38
lines changed

app/base/tools/Plates/SiteBase.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,4 +240,14 @@ public function summarize($text, $max_words = 10)
240240
}
241241
return implode(" ", array_slice($words, 0, $max_words)).' ...';
242242
}
243+
244+
/**
245+
* returns page regions
246+
*
247+
* @return array
248+
*/
249+
public function getPageRegions()
250+
{
251+
return $this->container->get('utils')->getPageRegions();
252+
}
243253
}

app/base/tools/Utils/Globals.php

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,31 +34,36 @@
3434
*/
3535
class Globals extends ContainerAwareObject
3636
{
37+
38+
/**
39+
* get page regions list
40+
*
41+
* @return array
42+
*/
43+
public function getPageRegions()
44+
{
45+
return array_filter(array_map('trim', explode(",", $this->getEnv('PAGE_REGIONS', 'menu,header,content,footer'))));
46+
}
47+
3748
/**
3849
* gets available block regions
3950
*
4051
* @return array
4152
*/
4253
public function getBlockRegions()
4354
{
44-
return [
55+
$out = [
4556
'' => '',
46-
4757
'after_body_open' => 'After Body-Open',
4858
'before_body_close' => 'Before Body-Close',
59+
];
4960

50-
'pre_menu' => 'Pre-Menu',
51-
'post_menu' => 'Post-Menu',
52-
53-
'pre_header' => 'Pre-Header',
54-
'post_header' => 'Post-Header',
55-
56-
'pre_content' => 'Pre-Content',
57-
'post_content' => 'Post-Content',
61+
foreach ($this->getPageRegions() as $region) {
62+
$out['pre_'.$region] = 'Pre-'.ucfirst(strtolower($region));
63+
$out['post_'.$region] = 'Post-'.ucfirst(strtolower($region));
64+
}
5865

59-
'pre_footer' => 'Pre-Footer',
60-
'post_footer' => 'Post-Footer',
61-
];
66+
return $out;
6267
}
6368

6469
/**

app/base/traits/ContainerAwareTrait.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,11 +238,12 @@ public function getHtmlRenderer()
238238
* gets env variable
239239
*
240240
* @param string $variable
241+
* @param mixed $default
241242
* @return mixed
242243
*/
243-
public function getEnv($variable)
244+
public function getEnv($variable, $default = null)
244245
{
245246
$env = (array)$this->getService('env');
246-
return $env[$variable] ?? null;
247+
return $env[$variable] ?? $default;
247248
}
248249
}

templates/frontend/layout.php

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,11 @@
1212
<?php $this->stop() ?>
1313

1414
<div class="container-fluid">
15-
<div class="menu">
16-
<?= $this->sitebase()->renderBlocks('pre_menu', $controller); ?>
17-
<?= $this->section('menu'); ?>
18-
<?= $this->sitebase()->renderBlocks('post_menu', $controller); ?>
19-
</div>
20-
21-
<div class="header">
22-
<?= $this->sitebase()->renderBlocks('pre_header', $controller); ?>
23-
<?= $this->section('header'); ?>
24-
<?= $this->sitebase()->renderBlocks('post_header', $controller); ?>
25-
</div>
26-
27-
<div class="content">
28-
<?= $this->sitebase()->renderBlocks('pre_content', $controller); ?>
29-
<?= $this->section('content'); ?>
30-
<?= $this->sitebase()->renderBlocks('post_content', $controller); ?>
31-
</div>
32-
33-
<div class="footer">
34-
<?= $this->sitebase()->renderBlocks('pre_footer', $controller); ?>
35-
<?= $this->section('footer'); ?>
36-
<?= $this->sitebase()->renderBlocks('post_footer', $controller); ?>
37-
</div>
15+
<?php foreach ($this->sitebase()->getPageRegions() as $region) :?>
16+
<div class="<?= $region; ?>">
17+
<?= $this->sitebase()->renderBlocks('pre_'.$region, $controller); ?>
18+
<?= $this->section($region); ?>
19+
<?= $this->sitebase()->renderBlocks('post_'.$region, $controller); ?>
20+
</div>
21+
<?php endforeach; ?>
3822
</div>

0 commit comments

Comments
 (0)