Heya!
It has been a painful road to work with WP these last few years and I've forgotten a few things about Joomla3
I'm developing a custom theme and I'd like to clean up the variables created within index.php and other template files, and somehow, I figure out I'll have to extend some HtmlDocument class to add a few snippets and methods in order to handle it better.
This may sound silly, but I'm focusing on having a little framework around the template to help me make faster and cleaner things .... Any advice?
Today I've been trying to find some advanced documentation about the templates but all I've got is making the basic template thing...
Thanks 4 your support.
Override view component
Moderator: General Support Moderators
Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Windows Defender SmartScreen Issues <-- please read this if using Windows 10.
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Windows Defender SmartScreen Issues <-- please read this if using Windows 10.
- effrit
- Joomla! Guru
- Posts: 846
- Joined: Sun Nov 12, 2017 2:21 pm
- Location: middle of Russia
- Contact:
Re: Override view component
hi
i guess u must post an example of things u tried to achieve, because it's hard to understand based on current information.
i guess u must post an example of things u tried to achieve, because it's hard to understand based on current information.
http://effrit.com/joomla | clean Word/Excel tables: http://r91228pz.bget.ru
-
- Joomla! Apprentice
- Posts: 6
- Joined: Mon Nov 05, 2018 4:08 pm
Re: Override view component
Yep, thanks for your response ...
I've got the code below from the beez3/index.php, to use as an example of how can a custom template in J3 be started.
This is what I want to avoid, to mess up so much code within the view. Its allright to access $this to retrieve the view's properties and parameters, but there's so much logic here to display things.
Is there some way to move this code away from the views? I was thinking about extending the view class or some HtmlDocument subclass to define some extra methods and getters, but any other tip would be nice.
thanks
//////////////////////////////////////////////////////////////////////////
I've got the code below from the beez3/index.php, to use as an example of how can a custom template in J3 be started.
This is what I want to avoid, to mess up so much code within the view. Its allright to access $this to retrieve the view's properties and parameters, but there's so much logic here to display things.
Is there some way to move this code away from the views? I was thinking about extending the view class or some HtmlDocument subclass to define some extra methods and getters, but any other tip would be nice.
thanks
//////////////////////////////////////////////////////////////////////////
Code: Select all
JLoader::import('joomla.filesystem.file');
// Check modules
$showRightColumn = ($this->countModules('position-3') or $this->countModules('position-6') or $this->countModules('position-8'));
$showbottom = ($this->countModules('position-9') or $this->countModules('position-10') or $this->countModules('position-11'));
$showleft = ($this->countModules('position-4') or $this->countModules('position-7') or $this->countModules('position-5'));
if ($showRightColumn === false && $showleft === false)
{
$showno = 0;
}
JHtml::_('behavior.framework', true);
// Get params
$color = $this->params->get('templatecolor');
$logo = $this->params->get('logo');
$navposition = $this->params->get('navposition');
$headerImage = $this->params->get('headerImage');
$config = JFactory::getConfig();
$bootstrap = explode(',', $this->params->get('bootstrap'));
$option = JFactory::getApplication()->input->getCmd('option', '');
// Output as HTML5
$this->setHtml5(true);
if (in_array($option, $bootstrap))
{
// Load optional rtl Bootstrap css and Bootstrap bugfixes
JHtml::_('bootstrap.loadCss', true, $this->direction);
}
// Add stylesheets
JHtml::_('stylesheet', 'templates/system/css/system.css', array('version' => 'auto'));
JHtml::_('stylesheet', 'position.css', array('version' => 'auto', 'relative' => true));
JHtml::_('stylesheet', 'layout.css', array('version' => 'auto', 'relative' => true));
JHtml::_('stylesheet', 'print.css', array('version' => 'auto', 'relative' => true), array('media' => 'print'));
JHtml::_('stylesheet', 'general.css', array('version' => 'auto', 'relative' => true));
JHtml::_('stylesheet', htmlspecialchars($color, ENT_COMPAT, 'UTF-8') . '.css', array('version' => 'auto', 'relative' => true));
if ($this->direction === 'rtl')
{
JHtml::_('stylesheet', 'template_rtl.css', array('version' => 'auto', 'relative' => true));
JHtml::_('stylesheet', htmlspecialchars($color, ENT_COMPAT, 'UTF-8') . '_rtl.css', array('version' => 'auto', 'relative' => true));
}
if ($color === 'image')
{
$this->addStyleDeclaration("
.logoheader {
background: url('" . $this->baseurl . "/" . htmlspecialchars($headerImage) . "') no-repeat right;
}
body {
background: " . $this->params->get('backgroundcolor') . ";
}");
}
JHtml::_('stylesheet', 'ie7only.css', array('version' => 'auto', 'relative' => true, 'conditional' => 'IE 7'));
// Check for a custom CSS file
JHtml::_('stylesheet', 'user.css', array('version' => 'auto', 'relative' => true));
JHtml::_('bootstrap.framework');
// Add template scripts
JHtml::_('script', 'templates/' . $this->template . '/javascript/md_stylechanger.js', array('version' => 'auto'));
JHtml::_('script', 'templates/' . $this->template . '/javascript/hide.js', array('version' => 'auto'));
JHtml::_('script', 'templates/' . $this->template . '/javascript/respond.src.js', array('version' => 'auto'));
JHtml::_('script', 'templates/' . $this->template . '/javascript/template.js', array('version' => 'auto'));
// Check for a custom js file
JHtml::_('script', 'templates/' . $this->template . '/javascript/user.js', array('version' => 'auto'));
require __DIR__ . '/jsstrings.php';
// Add html5 shiv
JHtml::_('script', 'jui/html5.js', array('version' => 'auto', 'relative' => true, 'conditional' => 'lt IE 9'));
?>
<!DOCTYPE html>
<html lang="<?php echo $this->language; ?>" dir="<?php echo $this->direction; ?>">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=3.0, user-scalable=yes"/>
<meta name="HandheldFriendly" content="true" />
<meta name="apple-mobile-web-app-capable" content="YES" />
<jdoc:include type="head" />
</head>
Last edited by toivo on Mon Nov 05, 2018 9:33 pm, edited 1 time in total.
Reason: mod note: added CODE tags
Reason: mod note: added CODE tags
- effrit
- Joomla! Guru
- Posts: 846
- Joined: Sun Nov 12, 2017 2:21 pm
- Location: middle of Russia
- Contact:
Re: Override view component
actually i prefer this "mess" because this is standard API and u learn it once.
but u can try inspect templates on Gatry or T3 frameworks - they always hide such code somewhere.
i guess the best solution is just make helper file with custom functions and include it.
but u can try inspect templates on Gatry or T3 frameworks - they always hide such code somewhere.
i guess the best solution is just make helper file with custom functions and include it.
http://effrit.com/joomla | clean Word/Excel tables: http://r91228pz.bget.ru
-
- Joomla! Apprentice
- Posts: 6
- Joined: Mon Nov 05, 2018 4:08 pm
Re: Override view component
thanks for your response!