Plugin: Add title in plugin sonata cms symfony - refs BT#20580

pull/4626/head
Christian 3 years ago
parent c7da1d985b
commit cb3f8a1860
  1. 32
      src/Chamilo/CoreBundle/Twig/Extension/ChamiloExtension.php
  2. 2
      src/Chamilo/ThemeBundle/Resources/views/Layout/base-layout.html.twig

@ -3,6 +3,8 @@
namespace Chamilo\CoreBundle\Twig\Extension;
use Twig\TwigFunction;
/**
* Class ChamiloExtension.
*
@ -27,7 +29,35 @@ class ChamiloExtension extends \Twig_Extension
*/
public function getFunctions()
{
return [];
return [
new TwigFunction('chamilo_page_title_get', [$this, 'getChamiloPageTitle']),
];
}
public function getChamiloPageTitle(): string
{
$urlPath = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
$urlPath = rtrim($urlPath, '/');
$parts = explode('/', $urlPath);
$title = end($parts);
$titleList = [];
$titleList[] = 'OFAJ'; // api_get_setting('Institution');
$titleList[] = 'PARKUR'; // api_get_setting('siteName');
$titleList[] = ucfirst(str_replace('-', ' ', $title)); // Page title
$titleString = '';
for ($i = 0; $i < count($titleList); $i++) {
$titleString .= $titleList[$i];
if (isset($titleList[$i + 1])) {
$item = trim($titleList[$i + 1]);
if (!empty($item)) {
$titleString .= ' - ';
}
}
}
return $titleString;
}
/**

@ -28,7 +28,7 @@
<title>
{% block title %}
{#{{ chamilo_settings_get('platform.institution') }} - {{ chamilo_settings_get('platform.site_name') }}#}
{{ chamilo_page_title_get('name') }}
{% endblock %}
</title>

Loading…
Cancel
Save