Close

Anywhere slider on all pages regardless of Home_page_top zone choosen

ryanspet
9 years ago
#7590 Quote
Avatar
  • 4
I am having an issue with the anywhere sliders showing up on all the pages, I only want it on the homepage at the top just under the menu. Any help would be appreciated.

The 'Index.cshtml' page is calling the correct file.

Thank you.

Here is the code: I have the slider in its own div so it was show up across the whole page. I want the slider to render in the one column and I want the rest of the page to be two columns.

_ColumnsTwo.cshtml

<!--this is where the slider is located.-->
<div class="center-1">
@Html.Widget("home_page_top")

</div>
<!--end slider-->
<div class="center-2">
    @RenderBody()  
  
</div>

<div class="side-2">
    @if (IsSectionDefined("left"))
    {
        @RenderSection("left")
    }
    else
    {
        @Html.Widget("left_side_column_before")
        @Html.Action("CategoryNavigation", "Catalog", new { currentCategoryId = currentCategoryId, currentProductId = currentProductId })
        @Html.Widget("left_side_column_after_category_navigation")
        @Html.Action("ManufacturerNavigation", "Catalog", new { currentManufacturerId = currentManufacturerId })
        @Html.Action("PopularProductTags", "Catalog")
        @Html.Action("PollBlock", "Poll", new { systemKeyword = "LeftColumnPoll" })
        @Html.Widget("left_side_column_after")
    }
Deni
9 years ago
#7601 Quote
Avatar
  • Moderator
  • 389
Hello,

You can do this by following these steps:

1. You must call the widget zone for the sliders only in your Index.cshtml file, putting its result in a section like this:


@section MainSlider
{
    @Html.Widget("home_page_main_slider")
}


2. You must see which is the layout of this view. If you want to show the slider on upper level(not in the direct layout of the Index view) you must check if the section is defined and define another section, which will be checked in the Layout of the Layout of Index.cshtml.

@if (IsSectionDefined("MainSlider"))
{
    @section MainSlider_UpperLevel1
    {
         @RenderSection("MainSlider")
    }
}


3. If this is the View where you want to show the slider then you must add this code:

@if (IsSectionDefined("MainSlider_UpperLevel1"))
{
    @RenderSection("MainSlider_UpperLevel1")
}



Let`s show you an example:

You have a slider in the Index.cshtml file and want to show it in the _Root.cshtml view. The layout of the Index.cshtml file is let`s say _ColumnsThree.cshtml. And the layout of _ColumnsThree.cshtml is the _Root.cshtml view.

So in Index.cshtml you must have:

@section MainSlider
{
    @Html.Widget("home_page_main_slider")
}



In _ColumnsThree.cshtml you must have:

@if (IsSectionDefined("MainSlider"))
{
    @section MainSlider_UpperLevel1
    {
         @RenderSection("MainSlider")
    }
}


In _Root.cshtml you must have:

@if (IsSectionDefined("MainSlider_UpperLevel1"))
{
    @RenderSection("MainSlider_UpperLevel1")
}




There are many other ways and one of them is this one:

1. Remove the widget zone from your Index.cshtml file.

2. Go to the view where you want to show the slider (for example: _Root.cshtml) and place this code:

@{
    var x = Url.RequestContext.RouteData.Values["controller"];
    @* var x = this.ViewContext.RouteData.Values["controller"]; You can use both this and the upper row to get the controller name *@
}

@if (x != null && string.Compare(x.ToString(), "Home", StringComparison.InvariantCultureIgnoreCase) == 0)
{
    @Html.Widget("home_page_main_slider")
}



Best Regards !
Best Regards,
Mladen Staykov
Nop-Templates.com
ryanspet
9 years ago
#7733 Quote
Avatar
  • 4
I am a little confused, do I need to create a new widget? I am using "@Html.Widget("home_page_main_top")"  should i have made a new one?


And I have that on the index page as shown below:

Thank you for all the help, I am very new to this.


This is my index.chtml

@{
    Layout = "~/Views/Shared/_ColumnsTwo.cshtml";
}

<div class="page home-page">
    <div class="page-body">
        @Html.Widget("home_page_main_top")
        @Html.Action("TopicBlock", "Topic", new { systemName = "HomePageText" })
        @Html.Action("HomepageCategories", "Catalog")
        @Html.Action("HomepageProducts", "Catalog")
        @Html.Action("HomepageBestSellers", "Catalog")
        @Html.Widget("home_page_before_news")
        @Html.Action("HomePageNews", "News")
        @Html.Action("HomePagePolls", "Poll")
        @Html.Widget("home_page_bottom")
    </div>
</div>

Here is my layout page:  _ColumnsTwo.cshtml
@{
    Layout = "~/Views/Shared/_Root.cshtml";
}
@{
    //current category ID
    int currentCategoryId = 0;
    if (Url.RequestContext.RouteData.Values["controller"].ToString().Equals("catalog", StringComparison.InvariantCultureIgnoreCase) &&
        Url.RequestContext.RouteData.Values["action"].ToString().Equals("category", StringComparison.InvariantCultureIgnoreCase))
    {
        currentCategoryId = Convert.ToInt32(Url.RequestContext.RouteData.Values["categoryId"].ToString());
    }


    //current manufacturer ID
    int currentManufacturerId = 0;
    if (Url.RequestContext.RouteData.Values["controller"].ToString().Equals("catalog", StringComparison.InvariantCultureIgnoreCase) &&
        Url.RequestContext.RouteData.Values["action"].ToString().Equals("manufacturer", StringComparison.InvariantCultureIgnoreCase))
    {
        currentManufacturerId = Convert.ToInt32(Url.RequestContext.RouteData.Values["manufacturerId"].ToString());
    }


    //current product ID
    int currentProductId = 0;
    if (Url.RequestContext.RouteData.Values["controller"].ToString().Equals("catalog", StringComparison.InvariantCultureIgnoreCase) &&
        Url.RequestContext.RouteData.Values["action"].ToString().Equals("product", StringComparison.InvariantCultureIgnoreCase))
    {
        currentProductId = Convert.ToInt32(Url.RequestContext.RouteData.Values["productId"].ToString());
    }
}

<div class="center-2">
    @RenderBody()  
   <!-- @Html.Widget("main_column_after")-->
</div>

<div class="side-2">
    @if (IsSectionDefined("left"))
    {
        @RenderSection("left")
    }
    else
    {
        @Html.Widget("left_side_column_before")
        @Html.Action("CategoryNavigation", "Catalog", new { currentCategoryId = currentCategoryId, currentProductId = currentProductId })
        @Html.Widget("left_side_column_after_category_navigation")
        @Html.Action("ManufacturerNavigation", "Catalog", new { currentManufacturerId = currentManufacturerId })
        @Html.Action("PopularProductTags", "Catalog")
        @Html.Action("PollBlock", "Poll", new { systemKeyword = "LeftColumnPoll" })
        @Html.Widget("left_side_column_after")
    }
</div>


Deni
9 years ago
#7737 Quote
Avatar
  • Moderator
  • 389
Hello,

I think this will help you:

The best and easiest way is to add custom widget zone in your SupportedWidgetZones.xml file in the Anywhere Sliders plug-in folder.

Name it as you wish. Example:   <WidgetZone>your_widget_zone</WidgetZone>

Now, go to your _ColumnsTwo.cshtml file and place this code where you want to see the slider:

@{
    var controllerName = Url.RequestContext.RouteData.Values["controller"];

    if (controllerName != null && string.Compare(controllerName.ToString(), "Home", StringComparison.InvariantCultureIgnoreCase) == 0)
    {
        @Html.Widget("your_widget_zone")
    }
}


Next, restart the application (or rebuild the solution).

Finally go to the admin site of the slider and select the new widget zone.

Now you must see the slider on the homepage.

Best Regards !
Best Regards,
Mladen Staykov
Nop-Templates.com
ryanspet
9 years ago
#7759 Quote
Avatar
  • 4
Thank you for all your help, the slider is on the homepage only!