How controller loads the layout in magento 2 - layout

I have developed a sample module in magento 2 that just prints the hellow world.there is only one controller and one layout file
controller
<?php
namespace MageClass\First\Controller\Test;
use Magento\Framework\View\Result\PageFactory;
use Magento\Framework\App\Action\Context;
class Helloworld extends \Magento\Framework\App\Action\Action
{
public function execute()
{
$this->_view->loadLayout();
$this->_view->renderLayout();
}
}
layout file
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
<referenceBlock name="content">
<block
template="helloworld.phtml"
class="Akhil\Test\Block\Helloworld"
name="helloworld_test_helloworld">
</block>
</referenceBlock>
</page>
Here my doubt is how this layout and controller is linked .when i accessed controller through browser by default this layout is loading. How it's linking layout and controller.
and i want to add another layout and controller in my module.so how to link these as when accessed the controller load the required layout

In Magento 2 Controller and layout file linked together with their
naming conventions.
So here you have created your controller file which is : app/code/MageClass/First/Controller/Test/Helloworld.php
Your layout file name is : app/code/MageClass/First/View/forntend/layout/helloworld_tes‌​t_helloworld.xml
Layout file name always depends on the controller name and its action
name.
Naming convention of layout file is - modulename_controllername_actionname.xml
Example 1:
Here your module name is "Helloworld" controller name is "Test" and your action name is "Helloworld".
so your layout file name should be - helloworld_test_helloworld.xml(modulename_controllername_actionname.xml)
Same thing now if you want to create new controller and new layout then again you need to like that using above conventions
Example :2
Here i am creating second controller "Test1" and action "Helloworld1".
so your controller path should be - app/code/MageClass/First/Controller/Test1/Helloworld1.php
so here your layout file name should be - helloworld_test1_helloworld1.xml(modulename_controllername_actionname.xml)
More reference refer this link - http://devdocs.magento.com/guides/v2.0/frontend-dev-guide/layouts/layout-types.html

Related

Nuxt.js - How to use layout inside layout

i have my deafult layout and i whant to make a page
with a layout and inside the layout a component that will be change insdie and chacnge the url to
how i do that with nuxt?
somthing like this pic:
i have my base layout in red
and i have a page layout in blue
now i have a links ander the Dashbord and i want whnan i click on the links the black box inside change only by other component and the url chacnge to
but i didnt the nuxt call again to the blue layout
I had a similar issue and solved by nesting pages using <nuxt-child/>.
GIF: How it works
GitHub: Nuxt.js Nested Routes Example Repository (not official)
Create a parent page like pages/group-foo.vue:
<template>
<div>
<!-- ... -->
<nuxt-child />
</div>
</template>
Then, create a directory with the same name as the parent page: pages/group-foo/.
Also, see these official documents:
Nested Routes
Dynamic Nested Routes
API: The Component

Liferay: localize layout template names

I have written a maven module, which contains my custom layout for liferay. The layout works fine but I also want it's name to be translated in a few languages.
Here's my liferay-layout-templates.xml file:
<?xml version="1.0"?>
<!DOCTYPE layout-templates PUBLIC "-//Liferay//DTD Layout Templates 6.2.0//EN" "http://www.liferay.com/dtd/liferay-layout-templates_6_2_0.dtd">
<layout-templates>
<custom>
<layout-template id="2_columns_layout-75_25" name="myLayout">
<template-path>/2_columns_layout-75_25/2_columns_75_25.tpl</template-path>
<wap-template-path>/2_columns_layout-75_25/2_columns_75_25.wap.tpl</wap-template-path>
<thumbnail-path>/2_columns_layout-75_25/2_columns_75_25.png</thumbnail-path>
</layout-template>
</custom>
</layout-templates>
I tried to delete name attribute and add language keys(which were the same to my template id) and values to my hook module, but it didn't work.
At first I was inclined to state that there's no built-in way to localize layout templates. However, I've looked up the JSP in question (in Liferay's html/portlet/layouts_admin/layout/layout_templates_list.jsp) and found the following line (shortened and edited):
<%= HtmlUtil.escape(LanguageUtil.get(locale,
"layout-template-" + layoutTemplateName, layoutTemplateName)) %>
So it looks like the localization keys that you'll need to use for translating your layout-template's name needs to be starting with "layout-template-" followed by the layout template's own name, e.g. given the xml from your question: layout-template-myLayout=My first localized layout template

How can i override this vendor layout file with my custom layout file in magento 2?

I have created a custom module in magento 2 and its layout file is located in
app/code/Learning/RewriteSales/view/adminhtml/layout/sales_order_view.xml .
but the system loads the layout from
vendor/magento/module-sales/view/adminhtml/layout/sales_order_view.xml
instead of my custom layout file?How can i override this vendor layout file with my custom layout file?

Sitecore.Placeholder("content") searching in wrong location for partial view

I have an MVC 5 application set up and it deploys to a Sitecore 8.0 Website. I have the Sitecore home item set up to render two "controls" - a PartialView Rendering called PageHeader and a Controller called HelloWorldController.
I am invoking these on a Layout which is assigned to the home item - the code that registers to that layout is as follows:
<p>Today's date is :#DateTime.Today.ToShortDateString()</p>
#Html.Sitecore().Placeholder("content")
For some reason, when I visit the homepage, I get this error:
The partial view '/views/renderers/Views/PageHeader.cshtml' was not found or no view engine supports the searched locations. The following locations were searched:
/views/renderers/Views/PageHeader.cshtml
However, my PageHeader doesn't live inside "/views/renderers/" . that directory doesn't exist. Does Sitecore generate this "/views/renderers/" from somewhere?
These is due to Mvc.RenderersViewFolder setting in App_Config\Include\Sitecore.Mvc.config, you need to patch the value:
<!-- MVC: Path to the base file folder that contains the views used for item renderings.
Default: "/views/renderers"
-->
<setting name="Mvc.RenderersViewFolder" value="/views/renderers" />
Patch the value to either empty string or whatever your views folder is.

Exception trying to load tab from ajax request using Ext.NET

I'm using asp.net mvc with ext.net and I'm trying to create a set of tabs that load information only when they are selected by the user.
I can manage to load a partial view into a tab/panel using the ContentFromAction functions:
But I can't figure out how to populate a tab/panel only when a tab is selected.
I've based my project on the Ext.NET MVC Examples Explorer version 2.5 code base and this code on the TabPanel > Basic > Ajax Load example found here
I've cut down the example as far as I can to reproduce the problem:
In my view I create the tab and configure the loader (exactly the same as the example project):
Index.cshtml
X.Panel()
.ID("Tab3")
.Title("Ajax Tab")
.BodyPadding(6)
.AutoScroll(true)
.Loader(X.ComponentLoader()
.Url(Url.Action("Ajax"))
.LoadMask(m => m.ShowMask = true)
.Params(new Parameter("containerId", "Tab3"))
.Mode(LoadMode.Html)
)
It correctly calls into my controller (exactly the same as the example project):
Axax_LoadController.cs
using System.Web.Mvc;
namespace Ext.Net.MVC.Examples.Areas.TabPanel_Basic.Controllers
{
public class Ajax_LoadController : Controller
{
public ActionResult Ajax(string containerId)
{
return View("Ajax");
}
}
}
Which in turn displays the appropriate view in the tab after it's been clicked on:
Ajax.cshtml (this works)
#using Ext.Net.MVC
<div>
<p>I am content loaded via Ajax when the tab is selected</p>
</div>
The problem begins if I try to add controls in my view, as follows:
Ajax.cshtml
#using Ext.Net.MVC
#{ var X = Html.X(); }
<div>
<p>I am content loaded via Ajax when the tab is selected</p>
#X.TextField().Text("I am a text field")
</div>
This fails with the exception:
ItemTag validation (_tkn_1): Reference token (init_script) was not found.
If I modify the file Ext call to return Html as follows:
Ajax.cshtml
#using Ext.Net.MVC
#{ var X = Html.X(); }
<div>
<p>I am content loaded via Ajax when the tab is selected</p>
#X.TextField().Text("I am a text field").ToHtmlString()
</div>
It correctly renders the following text in my selected tab:
I am content loaded via Ajax when the tab is selected
<#:item ref="init_script" index="0">Ext.create("Ext.form.field.Text",{renderTo:"App.id534c5fe0f159f3fb_Container",value:"I am a text field"});</#:item><div id="App.id534c5fe0f159f3fb_Container"></div>
I believe that the ext.net code is written by #geoffrey.mcgill on stack overflow so I'm hoping he can help rescue me.
You need to use a PartialViewResult. Please look at these examples.
Partial Content
Partial Items
Personally, I would recommend to follow the Partial Items example. You always can wrap any non-Ext.NET content in an Ext.NET Container. The benefit of this approach is the fact that you don't need to worry about destroying Ext.NET components if you reload the content. Though, anyway, I would recommend to set up explicit IDs for Ext.NET components in a partial view. At least, for top level components.

Resources