Does Sitecore 9.3 Helix support ASCX sub layouts - sitecore

Does Sitecore 9.3 Helix support ASCX user control referred in sub layout, if so, could you please share any reference?

Yes, it does support. In fact, this will work regardless of whether you follow Helix principles or not.
I guess that you want to mix renderings with sub layouts on a Sitecore MVC layout.
If your ASCX sub layout does not contain any postback logic and/or does not have another sub layout inside it then the easiest way will be to declare it in a View Razor file as follows:
#Html.RenderSitecoreSubLayout("~/Layouts/Sublayouts/YourSubLayout.ascx")
Alternatively, you can generate the inner sub layout at a code level and add it to a placeholder to get it rendered correctly, for example:
Sublayout yourSublayout = new Sublayout
{
Path = "~/Layouts/Sublayouts/YourSubLayout.ascx",
DataSource = yourItem,
Cacheable = true,
VaryByData = true,
VaryByParm = true
};
phYourPlaceholder.Controls.Add(yourSublayout);

Related

Sitecore 7 adding a sublayout dynamically based on tree structure

based on a single page view I am looking to have my content structure dynamically build the page.
So as an example: with a child item of GALLERY template, this would itself have sub-items using the GALLERY ITEM template which defines each of the images to be shown in a carousel; so an Editor can simply add multiple items and the carousel will scale accordingly rather than having fixed fields (banner, banner 2 etc)
Currently I am having an issue in understanding how my sublayout which defines the galleries HTML can automatically be included in this main page if that template is present.
Rather than an Editor having to manually add the Sublayout and define a datasouce to the gallery node I'd want the main page to iterate down the tree and observe there is a template for GALLERY therefore knowing it needs to use the sublayout and add it to the main page placeholder
On this principle the page will self build depending on what items an Editor adds to the page.
Any advice or sample code (using webforms) is appreciated; currently I am having to manually add sublayouts which seems to not be intuitive for Content Editors to assemble pages.
Thanks
If you are properly using and configuring the Page/Experience Editor, adding the sublayouts and data sources is a very intuitive process, and allows you to take full advantage of all the features and capabilities of Sitecore, in particular personalization and A/B testing. This is the recommended practice that you should follow.
That said, if you have extenuating circumstances that really prevent you from doing this, there is an older technique called "Presentation Inversion of Control" which pulls renderings from items associated via the content tree. It was useful prior to the "unified page editor" and datasource wizards which appeared in Sitecore 6.4. There are various approaches to this, but the simplest is a sublayout/web control that you place on the page.
The following code hasn't been tested by be on Sitecore 7:
public partial class Gallery: System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
PageItem page = Sitecore.Context.Item;
//custom item contains logic for finding items to include
foreach (Item galleryItem in page.GalleryItems)
{
string strDataSource = galleryItem.ID.ToString();
RenderingReference[] renderings =
galleryItem.Visualization.GetRenderings(Sitecore.Context.Device, false);
foreach (RenderingReference rendering in renderings)
{
rendering.Settings.DataSource = strDataSource;
this.Controls.Add(
rendering.RenderingItem.GetControl(rendering.Settings));
}
}
}
}
But really, you should just properly implement the Page Editor.

Sitecore 8.1 Header and Footer Composite Component

In Sitecore I have created base Template & Renderings for "Header, Top Menu, Logo, Search ,Login Button…etc that comes in Header across all Pages of the Site."
Also the same template & Rendering is using in other website so we can't set value in Standard field.
Now the problem is “suppose we have 100 pages in a Site then each page we have to go and add/update rendering & data source.
Is there any way that a “Header rendering” contains child rendering and by placing “Header rendering” render all its child renderings.
Header Composite Component ===>
Logo Component
Top Navigation Component
Search Component
There is a composite component module on the Sitecore Marketplace :https://marketplace.sitecore.net/Modules/C/Composite_components.aspx?sc_lang=en
This fill's your requirements exactly.
It works by creating a "Composite Component" item, then you add your renderings for your header to that component. E.g. Logo, Navigation etc...
Then in the standard values of your page templates, you add a new Composite Component rendering and set the datasource to the component item you created.
The module will then inject the renderings from the component item presentation into your current item. So you only have to update a single place to update all pages etc...
I have this running in a few production sites and it works well. It even supports the Experience Editor.
I don't think there's a solution out of the box. SxA solves this with Partial and Page Designs at site level. Just wrote a blog about it:
http://reinoudvandalen.nl/blog/sitecore-experience-accelerator-partial-designs-and-page-designs/
I also made something that might help you: Partial Layout Presets
http://reinoudvandalen.nl/blog/sitecore-partial-layout-presets/
It even allows you to store presets per site, but keep in mind that it injects composed layouts. If you modify the preset then it does not get applied to the pages where it was injected (though you might be able to pull something of with a shared datasource per site).
Lastly the obvious solution would be to create a page template per site so you'll be able to have standard values per site.
You may want to take a look at using Placeholder Fallback.
This will allow you to add components and renderings to a top level page and then the child pages would "fallback" to using the renderings inserted into the placeholder of the top level page in the item hierarchy. The editors can also insert page specific renderings on each child page if required.
If you do not want to custom code and only out of the box features then you could use Devices. You can find more information in the documentation about Set up a device layout. Once the device is created you can specify a different default device per site:
Now when you open the Presentation Details on the __Standard Values of your templates you can specify a different Layout or Renderings per device, i.e. different ones for AltSiteDevice

Sitecore replicate changes throw all the pages

I'm trying to implement a menu in sitecore page. Menu that will be available in all the pages.
I can do a rendering that goes to some specific datasource and assign the rendering to a placeholder inside Design Layout of the layout.
However how can they edit the datasource (order, ammount of elements, etc..) item in page A that will be also replicated in page B.
Without going through all the pages to change order, color, text, items etc...
To do that you will want to create a new data template that holds the shareable content on it. So it would have fields for navigation items etc... any setting that you wanted to be shared across pages.
Then in your rendering, you can set the Datasource to this item. Any changes to that item would be reflected across all pages that use it.
You should add the rendering to the standard values of your page templates and set the Datasource to your main default navigation item, then all new pages will get the navigation ready setup.
You need design your view in such a way that it should be editable in experience editor mode.
If you have implemented using Glass Mapper there is good section on how to use Edit Frame.
Also you can check below community blog. for more details.
https://community.sitecore.net/technical_blogs/b/sitecorejohn_blog/posts/render-field-values-for-mvc-solutions-using-the-sitecore-asp-net-web-cms

How to make a statically binded rendering editable via Experience Editor (Sitecore MVC)

So I have a layout view within Sitecore Mvc, this view contained a Controller Rendering that pulls in a header and footer navigation. Example:
#Html.Sitecore().Rendering("/sitecore/layout/renderings/some_rendering")
This specifies a Controller Rendering I've defined in Sitecore. This works great, except when I'm in the experience editor. It doesn't give me the ability to select this rendering. If I create a Placeholder and then define these navigation elements to this placeholder dynamically via Sitecore, then I can, but these navigational elements exist on every page of this layout, so I would like them statically placed instead of using a Placeholder, but I would still like the user to be able to select the navigation element in the experience editor (so I can create custom command to interact with this navigation, such as creating new links, etc).
Does anyone have an idea that will help me achieve this?
Use Edit Frame for that and create Custom Edit Frame Button for operations like adding new element to the navigation.
And remember to pass Datarsource ID or Path as a second parameter to the Html.Sitecore().Rendering() method:
#Html.Sitecore().Rendering("/sitecore/layout/renderings/some_rendering", new { DataSource = "{some-id-or-path}" })
Here is set of blog posts which can help you to understand how Edit Frames work and how to add them in Sitecore MVC solution:
https://visionsincode.wordpress.com/2015/01/08/how-to-use-editframe-in-sitecore-mvc/
https://www.cmsbestpractices.com/how-to-properly-use-sitecore-edit-frames/
https://briancaos.wordpress.com/2011/11/28/using-sitecore-editframe-in-pageedit/
You won't be able to remove the component or move it around the page (yeah, it's statically bound to one place on your layout), but you will be able to edit it's properties and datasource.
You can try to use GlassMapper views and statically inherit the view from the GlassView.
Then you'll be able to use Editable method to render the field.
But the consideration you need to take is that you'll not be able to set a datasource to the component from the page editor or content editor.
Instead of injecting the rendering through the Rendering method you should be able to use standart MVC RenderPartial.
I've used this approach on one of the projects I've been on and it worked.

Including MVC in existing Sitecore Project

we have a Sitecore Project up and running, that is based on the regular aspx/ascx approach.
Over time we would like to transform our existing sublayouts to MVC.
For test purposes I am trying to add a very simple MVC text component to the project, still I am stuck somehow.
What I have done so far:
Installed MVC 5.2
Installed WebPages
Added references and bindings
Added the MVC Scaffold
Right now, the Site does compile and run.
I have this Controller:
public class TextComponentController : Controller
{
public ActionResult Index()
{
return View();
}
}
And my view:
<h2>Index</h2>
<p>Hello from my View Template</p>
So absolutely nothing special here ;)
How can I create a sublayout (without a datasource) that just displays this simple MVC component?
In the very simplest way, you need to have the following:
Item for your page, the one that has URL; that is as normal in Sitecore
That page Item should have Layout assigned. From Presentation --> Details menu select at least a layout on that stage. If you do not have layout yet, you need to create a layout definition item under /Layout/Layouts folder and associate it with certain *.cshml file. Also mention that layout should have a placeholder where you will "inject"your rendering.
#Html.Sitecore().Placeholder("Main")
You need to create a Controller Rendering under /Layout/Renderings folder in Sitecore. Make sure you set Controller and Controller Action fields to your controller name and action method name.
Finally, go again to Presentation --> Details --> Edit --> Controls and add your newly created rendering into a placeholder that you have on your layout *.cshtml file.
That's all done.
Hope this helps!