?
avatar bdthemes
bdthemes
9 Nov 2014

Steps to reproduce the issue

  1. enable the SEF from global configuration
  2. go to any plugin and write: $current_template = JFactory::getApplication()->getTemplate(); for example go to: plugins/system/debug/debug.php and write this code here.
  3. go to menu and set any other template style for any menu item, for example if you have select default template as protostar so select beez3 for any menu item.

Expected result

default page need to show protostar and where you select beez3 for that menu item which need to show beez3 template.

When i turn off SEF from global configuration it's working Well.

Actual result

both page showing default template (protostar) :(

System information (as much as possible)

PHP Built On Windows NT RANA-PC 6.2 build 9200 (Unknown Windows version Business Edition) i586
Database Version 5.5.36
Database Collation utf8_general_ci
PHP Version 5.4.27
Web Server Apache/2.4.9 (Win32) OpenSSL/0.9.8y PHP/5.4.27
WebServer to PHP Interface apache2handler
Joomla! Version Joomla! 3.3.0 Stable [ Ember ] 30-April-2014 14:00 GMT
Joomla! Platform Version Joomla Platform 13.1.0 Stable [ Curiosity ] 24-Apr-2013 00:00 GMT
User Agent Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.111 Safari/537.36

Additional comments

maybe you think why it's need it for me? actually i want use it my own plugin for get current template directory.

same problem happen when i installed those plugin who use getTemplate() function there plugin.

some same issue plugin they used getTemplate method:
http://www.joomshaper.com/joomla-templates/helix-ii
http://www.seblod.com/

Votes

# of Users Experiencing Issue
1/1
Average Importance Score
5.00

avatar bdthemes bdthemes - open - 9 Nov 2014
avatar infograf768
infograf768 - comment - 9 Nov 2014

I first suggest you test on staging and not on 3.3.0 which is far away back (we are at 3.3.7 going on 3.4.0)

avatar Fedik
Fedik - comment - 9 Nov 2014

go to any plugin and write: $current_template = JFactory::getApplication()->getTemplate(); for example go to: plugins/system/debug/debug.php and write this code here.

where exactly?
you do it in the plugin file but outside of the plugin class, or you do it in some event method?
There can be different depend on the app state, when you tried get the template.

And I can add that there was some bug with App get/set template on old joomlacode tracker ... but cannot find..

avatar bdthemes
bdthemes - comment - 10 Nov 2014
  1. if you write outside in plugin class same result
  2. if you write inside _construct function same result

    This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/5076.
avatar Bakual
Bakual - comment - 10 Nov 2014

I wouldn't expect it to work in the constructor. The constructor is executed before the routing is done and thus the template isn't set correctly yet.
You need to do this in the onAfterRoute event or later.

Closing this as expected behaviour.

avatar Bakual Bakual - close - 10 Nov 2014
avatar zero-24 zero-24 - close - 10 Nov 2014
avatar Bakual Bakual - change - 10 Nov 2014
Status New Closed
Closed_Date 0000-00-00 00:00:00 2014-11-10 07:38:39
avatar bdthemes
bdthemes - comment - 10 Nov 2014

I think you not clear about it or i could not understand you.

actually i need to include a file in plugin from current template so it's need to declare on top of the plugin file and it's working well until SEF enable.

my example code:
// Import the shortcodes override from current template if the file exists
$shortcode_template = JPATH_THEMES.'/'.JFactory::getApplication()->getTemplate().'/html/plg_bdthemes_shortcodes/shortcodes.php';
if (file_exists($shortcode_template)) {
require_once($shortcode_template);
}

it's perfectly work without SEF and when i enable SEF it's not work anymore because template has been changed to default template.

This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/5076.

avatar Fedik
Fedik - comment - 10 Nov 2014

@bdthemes just do it in the onAfterRoute event, as @Bakual wrote :wink:
Your approach (write the code in the plugin file, out of the plugin class) is wrong.

avatar Bakual
Bakual - comment - 10 Nov 2014

Have a look at http://docs.joomla.org/J3.x:Creating_a_Plugin_for_Joomla how to write a plugin.

The important thing is to run your code withing an event method.
In your case, you need to use a system plugin event: http://docs.joomla.org/Plugin/Events/System

Currently, you're code runs basically in the onAfterInitialise event, because there the plugins are loaded for the first time.
When you have SEF enabled, the routing is the process where the Itemid is determined and from there the active template is derived. When you have SEF disabled, there is no need for that step because the Itemid is already present plain in the URL.
That explains why your code works without SEF and doesn't work with SEF.

As explained, just put your code into an event where the routing has been completed and the Itemid is present. The earliest event for that is the onAfterRoute event. There are also other events possible: http://docs.joomla.org/Plugin/Events/System.

avatar zero-24 zero-24 - change - 7 Jul 2015
Labels Added: ?

Add a Comment

Login with GitHub to post a comment