Seperate action page for new layouts in yii - layout

I am a yiibie, I created a new layout named "landing.php" in layouts folder, but when i run it, it opens the index.php. How can I have a separate action page for landing.php.
So either i run main.php or landing.php they should be running.

You can change the layout for each action in the controller adding in the function action
$this->layout = "layoutName";
or for entire controller adding the attribute
public $layout = "layoutName";
This work in Yii 1.x and Yii 2.x

Related

Empty Portlet body in custom portlet

We have a custom portlet having an MVCActionCommand invoked from another portlet. MVCActionCommand executed successfully but on the page it's showing empty portlet body in results page. Expected is jsp is having data to render based on response and we are having static html code like input text and tabs to filter data.
We are using below code in Controller to redirect to JSP
actionResponse.setRenderParameter("jspPage", "/META-INF/resources/results_page.jsp);
Main issue is, this we are facing only in PROD environment, UAT & local environment it's working fine
Below is my portlet #component values.
#Component(
immediate = true,
property = {
"com.liferay.portlet.display-category=category.search",
"com.liferay.portlet.instanceable=false",
"javax.portlet.init-param.template-path=/",
"javax.portlet.init-param.view-template=/view.jsp",
"javax.portlet.init-param.add-process-action-success-action=false",
"javax.portlet.name=SearchResults",
"javax.portlet.resource-bundle=content.Language",
"com.liferay.portlet.add-default-resource=true",
"javax.portlet.security-role-ref=power-user,user"
},
service = Portlet.class
)
Redirection to page is happening correctly but portlet body is empty. In this page I have some static HTML code in this page and its also not loading.
Why different environments have different behavior for same piece of code? Below is the screen shot.
I would recommend that you use the "mvcPath" parameter since "jspPath" is deprecated. Example usage: EditUserOrganizationsMVCActionCommand.java

How to tell the context an Xpage is running in - Sidebar

I have an Xpage that I want to put in a panel in the sidebar.
I only want the entry part to be in the panel, so I made a ccEntry Custom Control and I put it into an Xpage for the main app and into an Xpage that is for the widget and ONLY contains the ccEntry form.
When I run the widget in the sidebar and hit submit, the code in the submit (which says previous) goes to the entire page. I want to put something in the button to like if I am in a sidebar then do this else do this. So if I could grab the name of the Xpage in a field that would do, but I cannot figure out how to do this.
Try view.getPageName(). That will give you a string of the current XPage's name in the format "/somepage.xsp".
#Jesse's solution makes something nasty: the control gets tightly coupled to its surroundings. You have two options:
Redirect
Define custom control's parameter with page name or URL to redirect to. Your submit button then redirects to that URL (accessed by compositeData.param). Your pages define different parameter value.
Navigation (preferred)
Your submit button's last command is simple line of code:
return "submitted";
Your pages for app/sidebar define different navigation rule target for the same rule: "submitted".

Zf2 define child layout for entire module

I want to create a navigation for Application module as the main navigation containing all module, and a navigation for each others modules containing all controllers of this module.
It will rendered at the last like tabs with subs tabs depending of the active page.
I want to do this with child layout, without inserting $view->layout()->addchild(..) in each action of each controllers of each module.
In each Module's Module.php file you can attach a custom event in the onBootstrap method to set whichever template you wanted:
//Attached in the onBootstrap method of Module.php
public function determineLayoutEvent(\Zend\Mvc\MvcEvent $event) {
$view = new \Zend\View\Model\ViewModel();
$view->setTemplate('custom/custom_layout');
$event->setViewModel($view);
}
I would do something like that^^.
There might be a hiccup or two with the code I've given when appending the actual view from the controller, but this should be a decent start.

Yii is not rendering theme

I'm having a strange issue with Yii and a theme. I set it in config/main.php like:
'theme'=>'themeName',
as usual. But when I try to render a view, it is rendered as is, without any layout, as if I called:
$this->renderPartial
I double check that I don't call for renderPartial, the themes seem to be equal to all the others theme I've done. What can be this issue about?
Thank's for any help, I'm going out of mind on this...
Here is the structure and syntax that you should have to check
-yiiroot
-!-!protected
-!-!-!controllers
-!-!-!-!TestController.php
-!-!themes
-!-!-!themeName (it was the one that you have set on config file)
-!-!-!-!views
-!-!-!-!-!layouts
-!-!-!-!-!-!main.php // It would be default what if public $layout has not been overwriten or the layout file which has been set was not found
-!-!-!-!-!test
-!-!-!-!-!-!viewName.php
On controller TestController
public $layout is main as default or is overwritten there
in actionIndex you set $this->render('viewName');
If you rendered your page by method renderPartial() directly in controller, you would not get the layout template for sure
render() is commonly used to render a view that corresponds to what a
user sees as a "page" in your application. It first renders the view
you have specified and then renders the layout for the current
controller action (if applicable), placing the result of the first
render into the layout. It then performs output processing (which at
this time means automatically inserting any necessary tags
and updating dynamic content) and finally outputs the result.
renderPartial() is commonly used to render a "piece" of a page. The
main difference from render() is that this method does not place the
results of the render in a layout. By default it also does not perform
output processing, but you can override this behavior using the
$processOutput parameter.
renderFile() is a low-level method that does the grunt work of
rendering: it extracts the data variables in the current scope and
then runs the view code. The other two methods internally call this
one, but you should practically never need to call it yourself. If you
do, keep in mind that you need to pass in a file path (not a view
path).
Reference: Yii difference between rendering functions

Orchard CMS: Using different Layout for Anonymous users

I would like to use a different layout view for anonymous users. I have tried using url alternates and I am not sure how I can create a layout for anonymous users since there is no particular url for them.
The idea is that, if a new user visits the site I want to show a splash screen with very limited information with an option to register/ login to view the full site. This splash screen will have a completely different layout / look and feel from the rest of the site.
I tried using the Anonymous user layer but all I could do was move widgets (maybe I am missing something).
Any help would be greatly appreciated.
Thanks!
There is no out of the box solution but you can do something like this to get what you want:
Add new layout in a file with the name of your choosing - for example, you could name it Splash.cshtml.
Add the code below to the top of your Layout.cshtml template:
#if (WorkContext.CurrentUser == null) {
#Display.Splash()
return;
}
The code will check if the user is logged in. If it's not, it will render the content of your Splash.cshtml template, and stop the rendering of the rest of the Layout.cshtml template.
If you need to display any of the widgets in your Splash.cshtml template, you could add it by simply adding #Display(Layout.NameOfTheZone) where you should replace NameOfTheZone with the actual name of the zone you're using inside the Layout.cshtml template. Generally, anything that you use inside Layout.cshtml template with the Model object, you can use through Layout object inside any of your views.

Resources