How to set container-title in custom administrator component Topic is solved

For Joomla! 3.x Coding related discussions, please use: http://groups.google.com/group/joomla-dev-general

Moderator: ooffick

Forum rules
Please use the mailing list here: http://groups.google.com/group/joomla-dev-general rather than this forum.
Post Reply
Jens321
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Fri Nov 08, 2019 3:24 pm

How to set container-title in custom administrator component

Post by Jens321 » Fri Nov 08, 2019 3:41 pm

Hi,
I'm beginning to build a small custom component that I want to display in the administrator section.
I'm starting off not using the MVC model, and just displaying the stuff I need directly in the root component php file, meaning e.g. joomla/administrator/components/com_mycomponent/mycomponent.php

That works fine, but what I am wondering is, how I set any content to the default header that is displayed when I show my component.
Currently it looks like the picture in the attachment. The dark blue title bar is collapsed, because it doesn't have content in the part

Code: Select all

<div class="container-title"></div>
How do I fill this with a title from code?

To clarify: I do not mean to set the HTML title. That already works.

This is the code in my root php file:

Code: Select all

<?php

// Protect from unauthorized access
defined('_JEXEC') or die();

$document = JFactory::getDocument();
$document->setTitle('Data Editor');

$type = $_GET['type'];
$action = $_GET['action'];

if (empty($type)) {
	include_once(JPATH_COMPONENT_ADMINISTRATOR . '/sites/mainmenu.php');
} else {
	switch ($type) {
		case 'literature': {
			echo "Literatur";
			break;
		}
		case 'products': {
			echo "Produkte";
			break;
		}
	}
}
As you see, it's quite basic currently.

Thank you in advance.

Best regards
Jens

Edit:
I mean, I can just do it via JavaScript by including a script like this on the page, but I recon there is a smarter way...

Code: Select all

<script>
	jQuery(document).ready(function() {
		jQuery('.container-title').html('<h1 class="page-title">What a Wonderful Title</h1>');
	});
</script>
You do not have the required permissions to view the files attached to this post.
Last edited by toivo on Fri Nov 08, 2019 11:41 pm, edited 1 time in total.
Reason: mod note: moved from 3.x General Questions

User avatar
toivo
Joomla! Master
Joomla! Master
Posts: 11475
Joined: Thu Feb 15, 2007 5:48 am
Location: Suzhou, China

Re: How to set container-title in custom administrator component

Post by toivo » Mon Nov 11, 2019 3:04 am

Welcome to the Joomla forums!

Components that follow the MVC model have the following code in the file view.html.php of the view, for example administrator/components/com_banners/views/banners, to take care of the blue bar:

Code: Select all

		JToolbarHelper::title(JText::_('COM_BANNERS_MANAGER_BANNERS'), 'bookmark banners');
Toivo Talikka, Global Moderator

Jens321
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Fri Nov 08, 2019 3:24 pm

Re: How to set container-title in custom administrator component

Post by Jens321 » Mon Nov 11, 2019 9:05 am

Thanks a lot, that works perfectly!
toivo wrote:
Mon Nov 11, 2019 3:04 am
Welcome to the Joomla forums!

Components that follow the MVC model have the following code in the file view.html.php of the view, for example administrator/components/com_banners/views/banners, to take care of the blue bar:

Code: Select all

		JToolbarHelper::title(JText::_('COM_BANNERS_MANAGER_BANNERS'), 'bookmark banners');


Post Reply

Return to “Joomla! 3.x Coding”