-
AuthorPosts
-
doorknob Friend
doorknob
- Join date:
- December 2013
- Posts:
- 36
- Downloads:
- 0
- Uploads:
- 1
- Thanks:
- 2
- Thanked:
- 20 times in 1 posts
January 1, 2014 at 4:43 pm #193387I thought it worth sharing my experience in developing a template block for T3 Blank because it took a long time to track down the cause of an issue that I created inadvertently.
When I loaded the template into the live site and started to configure it, I found that the layout tab was empty and I got an error message “The layout cannot be loaded. There might be some errors in the layout file.”. It didn’t take long to find out that this was happening because the t3 template (modified T3 Blank) was not the default template but it took a lot longer to find out why this caused a php error.
One of the modifications had been to add a new template block to add some scripts to the template for miscellaneous purposes,. One of the new processes loads a helper class from a file in the template directory structure. This works fine when the template is used in the frontend in the normal way but seemed to be triggering a php error when run in the backend.
If the template is run in the normal way, it can only be active if it is the default template in which case the code:
JFactory::getApplication()->getTemplate();
will always return the name of the correct template. I was using this to create the path when loading the helper file and to create the URLs for js files. Unfortunately, when the template manager style editing page creates the layout, the above code may returns the name of the wrong template if t3 blank is not the default template.T3 has a method that returns the name of the template when working in the backend so I tried using ‘isAdmin()’ to determine when to use the regular Joomla method and when to use the T3 method. That didn’t work because when creating the layout in the backend, isAdmin() returns FALSE. Unfortunately we can’t use the T3 method in all circumstances because it returns an empty string in the frontend. I finally concluded that the only safe way to get the template name in a template block file is:
$template = T3::getTemplate(true);
if (empty($template)) {
$template = JFactory::getApplication()->getTemplate();
}I hope this saves some frustration for anyone doing something similar.
3 users say Thank You to doorknob for this useful post
alexsmirnov Friendalexsmirnov
- Join date:
- July 2012
- Posts:
- 786
- Downloads:
- 1
- Uploads:
- 226
- Thanks:
- 226
- Thanked:
- 163 times in 119 posts
March 31, 2014 at 4:35 pm #528812Much appreciated!
On what Joomla version did you play with this please?
doorknob Frienddoorknob
- Join date:
- December 2013
- Posts:
- 36
- Downloads:
- 0
- Uploads:
- 1
- Thanks:
- 2
- Thanked:
- 20 times in 1 posts
March 31, 2014 at 6:36 pm #528827<em>@alexsmirnov 419057 wrote:</em><blockquote>On what Joomla version did you play with this please?</blockquote>
It will have been whichever of the J3.2.n line was current at the time (3.2.1?)
1 user says Thank You to doorknob for this useful post
alexsmirnov Friendalexsmirnov
- Join date:
- July 2012
- Posts:
- 786
- Downloads:
- 1
- Uploads:
- 226
- Thanks:
- 226
- Thanked:
- 163 times in 119 posts
March 31, 2014 at 7:12 pm #528832Cheers once again.
-
AuthorPosts
This topic contains 4 replies, has 2 voices, and was last updated by alexsmirnov 10 years, 7 months ago.
We moved to new unified forum. Please post all new support queries in our New Forum