How to change load layout in Joomla view? - joomla

By default parent::display($tpl); loads components/com_my_component/views/my_component/tmpl/default.php, but in some cases i need to load other php file which is in the same folder near default.php (for example components/com_my_component/views/my_component/tmpl/lol.php). How to do this from view.html.php.
P.S.
Tried load loadTemplate and setLayout methods with no luck.

Solved the problem by myself. Need to use the method setLayout and pay attention to the input syntax
$this->setLayout('dafault:lol');
parent::display($tpl);

By default, joomla looks for the layout keyword in the URL to decide which layout to display. If this variable is empty or not present then the tmpl/default.php layout will be loaded.
By editting your view.html.php file you can set the default layout by using the JView API, e.g. $this->setLayout('lol') will make the URL example.com/yourview equivalent to example.com/yourview?layout=lol.
However, this change alone will result in Joomla overriding it's default behaviour so that the layout request will be ignored. This means that the request example.com/yourview?layout=lmao will also display example.com/yourview = example.com/yourview?layout=lol
You can solve this easily by adding a condition around the setLayout function so that only if the layout keyword is not present then you will set the default layout to lol, e.g.
<?php
# ...
function display($tpl = null) {
# ...
# Edit : Set the default layout to 'lol'
$layout = JRequest::getWord('layout', '');
if (empty($layout)) $this->setLayout("lol");
// Display the view
parent::display($tpl);
}
# ...

I keep coming back to this and I've yet to find a satisfying solution.
What does work, from J1.5 right up to J3.4, for me has always been to set the $tpl variable in view.html.php
If $tpl is empty or "" then tmpl/default.php is displayed by default.
If you change $tpl to a string, e.g. $tpl="stacker" then it will look for and display tmpl/default_stacker.php
I've seen various differing theories on changing it earlier in the MVC so that it doesn't need the default_ pretext. e.g. tmpl/stacker.php
None have worked for me.

Related

phpbb variable empty on custom page

I have a phpbb 3.1 forum, where I have put a html portal, (using the custom page tutorial)
I have included functions.php so I can use {S_USERNAME} and everything with the S_ in that page...
but, now I want to put the forum statistics, using, for example:
{TOTAL_USERS_ONLINE}
{LOGGED_IN_USER_LIST}
{TOTAL_POSTS}
and so on
The variables, are empty when using them in my page... is there any problem? I need to add something more than that file?
thanks!
The variables are mentioned are initialized in the page_header function in functions.php
In custom pages you always call that function to initialize common variables like the S_ variables you mentioned.
Since the loading of online users is a little heavier and not needed on every page, the function has a parameter $display_online_list to enable it.
Check the method signature and set $display_online_list to true
To display TOTAL_POSTS, you will need to add a bit of code, see the assign_vars call in index.php, $config is a global variable which should be available in every page.

Set homepage from theme's layout

I am trying to set a CMS homepage via a theme's local.xml layout update file in the <cms_index_index> node. I swear I've seen functions to change the store configuration temporarily within a layout node (but maybe I dreamt it), but I'm having trouble finding the layout function in classes like Mage_Core_Block_Abstract and its children classes.
For reference, I've checked in Mage_Cms_IndexController and found the function which renders the homepage:
public function indexAction($coreRoute = null)
{
$pageId = Mage::getStoreConfig(Mage_Cms_Helper_Page::XML_PATH_HOME_PAGE);
if (!Mage::helper('cms/page')->renderPage($this, $pageId)) {
$this->_forward('defaultIndex');
}
}
Or, am I doing this completely the wrong way? What would be best practice for a problem like this? I do not want to add a store view for the new theme, as the new theme is for mobile platforms and requires the same settings from the store view. Thanks guys!
This is not possible. The layout configuration is not invoked until after checks occur to see if there is a valid page which has been specified; because these checks fail, the Default router will match and (by default) the application will display the 404 page.

Change layout in controller depending on url

I have controller PlayerController and actions inside: View, Info, List.
So on urls "/Player/View" i get result with default Layout.
I want to get result with different Layout on request "/External/View".
How can i achieve this?
Although you can override the layout from the controller as has been suggested in another answer, in my opinion this means the controllers are getting just too involved in determining what the UI will be. Best to leave this purely to the Views to decide.
The closest to what you're asking is to do this in your current "~/Views/_ViewStart.cshtml":
#{
if(Context.Request.Path.StartsWith("/External", StringComparison.OrdinalIgnoreCase))
Layout = "~/Views/_ExternalLayout.cshtml";
else
Layout = "~/Views/_Layout.cshtml";
}
Where "~/Views/_ExternalLayout.cshtml" is your alternative layout.
Might want to check the leading "/" is correct on there, I can't remember if it is.
If you put this in the existing _ViewStart, then any view that is being rendering in response to a url starting with "/External" will use this new layout, otherwise the 'normal' one will be used.
Another approach is to use the routing table to add a route value that can be used here to make a layout decision; but I've gone for this approach to keep it simple.
You can specify which layout should be used when returning a view inside your 'ExternalController' controller action.
return View("View", "~/Views/Shared/_AnotherLayout.cshtml")

Create base jqgrid

I have a website with several views, and most of them have a jqGrid on them.
I'd like to set some base options on all my jqgrids. For example, I'd like the view option to always be set to true, and the search option to always be set to false.
Additionally, there are several that I'd like to have the same button labels.
Is there any way to do this with a jqGrid?
Look at the answer which shows how to set default settings jQuery.jgrid.nav. In your case it would be
jQuery.extend(jQuery.jgrid.nav,
{search:false,view:true, viewtext:"View label", viewtitle:"View tooltip"}
);
Other default settings you can change in the same way using jQuery.jgrid.del, jQuery.jgrid.view and of course jQuery.jgrid.defaults.
You don't need to place the code inside of jQuery(document).ready(function() {/**/});. It is enough just ecxecute the code like jQuery.extend(jQuery.jgrid.nav, {search:false,view:true}); inside a JavaScript file loaded after the jquery.jqGrid.min.js.
You could add an additional script tag to your HTML that references a JS file with some base configuration stuff for the grid in a $().ready(function() {}); block.
You could also create a base configuration function or variable that you store in that external JS, and reference that configuration on each view page.
I would prefer to write the base function, and not the ready event handler as the ready handler will NOT run at a predictable time. You won't know if it properly ran before your jqGrid configure function ran.

TYPO3: Change plugin from USER to USER_INT type

I have a working TYPO3 extension. It is attached this wiki page. How can I change the code of this extension so it is of the USER_INT type? I.e. I don't want TYPO3 to cache the output of this plugin, and want TYPO3 to invoke the extension ever time a page that uses the extension, i.e. disable the caching for this extension.
To disable caching for your extension go to your piX/class.tx_XXX_piX.php file and remove the following line (below your class declaration):
var $pi_checkCHash = true;
You also need to add the following line in the main method (below $this->pi_loadLL();):
$this->pi_USER_INT_obj=1; // Configuring so caching is not expected. This value means that no cHash params are ever set. We do this, because it's a USER_INT object!
grunwalski it's the opposite you have to change this:
t3lib_extMgm::addPItoST43($_EXTKEY,'piX/class.tx_yourextension_piX.php','_piX','list_type',1);
to this:
t3lib_extMgm::addPItoST43($_EXTKEY,'piX/class.tx_yourextension_piX.php','_piX','list_type',0);
The simpliest way to solve your problem is to go back to Extension Maganer, select your extension, choose "Edit in Kickstarter" from the dropdown menu, and then select the corresponding Frontend plugin to edit it's properties.
Check the first checkbox which means that you want your plugins to be rendered as USER_INT cObjects. After that click the View result button, uncheck all custom PHP files (your own code, like modules and plugins) on the right side and click the WRITE button. Please be careful. If you don't uncheck the checkboxes of your own files, they will be overwritten with dummy files.
The correct and comlete way to do this is a combination of the answers of #arturh and #Mehdi Guermazi:
change the last parameter in the addPItoST43() call in ext_localconf.php from 1 to 0
remove the var $pi_checkCHash = true; line from the property definitions in the head of the pi1 class.
add the $this->pi_USER_INT_obj=1; line to the start of the main() function in pi1.
These changes are identical to what you will get when you use the kickstarter method explained in the solution of #bencuss.
When you have created your extension with Kickstarter you also have to go to the file [yourextension]/ext_localconf.php and change this line
t3lib_extMgm::addPItoST43($_EXTKEY,'piX/class.tx_yourextension_piX.php','_piX','list_type',0);
to this:
t3lib_extMgm::addPItoST43($_EXTKEY,'piX/class.tx_yourextension_piX.php','_piX','list_type',1);
Edit the file setup.txt of your extension "myext". Change "USER" into "USER_INT".
plugin.tx_myext = USER_INT
plugin.tx_myxt {
This extension will never be cached.

Resources