Skip to content

Commit ed1a749

Browse files
committed
Fix template preview
1 parent 7978f28 commit ed1a749

File tree

2 files changed

+23
-17
lines changed

2 files changed

+23
-17
lines changed

libraries/src/Document/Renderer/Html/ModulesRenderer.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
\defined('JPATH_PLATFORM') or die;
1212

13+
use Joomla\CMS\Component\ComponentHelper;
1314
use Joomla\CMS\Document\DocumentRenderer;
1415
use Joomla\CMS\Factory;
1516
use Joomla\CMS\Helper\ModuleHelper;
@@ -42,8 +43,26 @@ public function render($position, $params = array(), $content = null)
4243
$user = Factory::getUser();
4344
$frontediting = ($app->isClient('site') && $app->get('frontediting', 1) && !$user->guest);
4445
$menusEditing = ($app->get('frontediting', 1) == 2) && $user->authorise('core.edit', 'com_menus');
46+
$modules = ModuleHelper::getModules($position);
4547

46-
foreach (ModuleHelper::getModules($position) as $mod)
48+
// Prepend a dummy module for template preview
49+
if ($app->input->getBool('tp') && ComponentHelper::getParams('com_templates')->get('template_positions_display'))
50+
{
51+
$dummy = (object) [
52+
'id' => 0,
53+
'module' => '',
54+
'params' => '',
55+
'showtitle' => 0,
56+
'title' => $position,
57+
'position' => $position,
58+
'content' => $position,
59+
'contentRendered' => true,
60+
];
61+
62+
array_unshift($modules, $dummy);
63+
}
64+
65+
foreach ($modules as $mod)
4766
{
4867
$moduleHtml = $renderer->render($mod, $params, $content);
4968

libraries/src/Helper/ModuleHelper.php

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,9 @@ public static function &getModule($name, $title = null)
8484
public static function &getModules($position)
8585
{
8686
$position = strtolower($position);
87-
$result = array();
88-
$input = Factory::getApplication()->input;
89-
90-
$modules =& static::load();
91-
92-
$total = \count($modules);
87+
$result = array();
88+
$modules = &static::load();
89+
$total = \count($modules);
9390

9491
for ($i = 0; $i < $total; $i++)
9592
{
@@ -99,16 +96,6 @@ public static function &getModules($position)
9996
}
10097
}
10198

102-
if (\count($result) === 0)
103-
{
104-
if ($input->getBool('tp') && ComponentHelper::getParams('com_templates')->get('template_positions_display'))
105-
{
106-
$result[0] = static::createDummyModule();
107-
$result[0]->title = $position;
108-
$result[0]->position = $position;
109-
}
110-
}
111-
11299
return $result;
113100
}
114101

0 commit comments

Comments
 (0)