Put Product on Individual Topic Pages

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
5 лет назад
Hi,

Is it possible to put products on certain topic pages?

I've created a widget that will show in the Topic page template but when I select product to show in this widget it will show on all Topic pages.

EG. I'm creating a topic called 'Coats that are great for Spring' and would like to show 6 products on that Topic.

Thanks,

John
5 лет назад
Customization needed. :)


5 лет назад
jslater wrote:
Hi,

Is it possible to put products on certain topic pages?

I've created a widget that will show in the Topic page template but when I select product to show in this widget it will show on all Topic pages.

EG. I'm creating a topic called 'Coats that are great for Spring' and would like to show 6 products on that Topic.

Thanks,

John


Hello jslater,


to add a slider to a specific Topic page, you need to check what page you are currently on and show the slider widget-zone on the required Topic page only.

You can achieve this, by adding the following code in the View for the topic pages, where you must have added your new widget-zone:

@if(Model.SystemName.Equals("SYSTEM_NAME_OF_TOPIC_PAGE", StringComparison.CurrentCultureIgnoreCase)) {
    YOUR_WIDGET_ZONE_GOES_HERE
}


If you want to have the same slider on multiple pages, you can use the following approach:

var topicNames = "Topic_1,Topic_2,Topic_3";

var topicName = topicNames.Split(",").ToList().FirstOrDefault(x => x.Equals(Model.SystemName, StringComparison.CurrentCultureIgnoreCase));

if(topicName != null)
{
    YOUR_WIDGET_ZONE_GOES_HERE
}




Hope this was helpful.

Regards,
Valentin.
5 лет назад
Thanks that was very helpful.

On a related note, is there a way of determining the content of a widget zone and performing an if statement on it before it is output?

For example using your NopTemplates JCarousel plugin, I've created two carousels named Printing Overview and Delivery Information and set them to the same custom widget zone topic_after_content.

On my topic page is there a way I can perform an if statement somewhere on the lines of the below

*Viewing my topic page which is named "Printing Overview"*


@if (Model.SystemName.Equals(name_of_JCarousel_in_topic_after_content_widgetZone, StringComparison.CurrentCultureIgnoreCase))
{
    @await Component.InvokeAsync("Widget", new { widgetZone = "topic_after_content" })
}



I only ask this as currently if I want to have different JCarousels on different Topic pages I'm having to create new custom widget zones every-time which isn't ideal.

Any suggestions would be most welcome.

Thanks
5 лет назад
jslater wrote:
Thanks that was very helpful.

On a related note, is there a way of determining the content of a widget zone and performing an if statement on it before it is output?

For example using your NopTemplates JCarousel plugin, I've created two carousels named Printing Overview and Delivery Information and set them to the same custom widget zone topic_after_content.

On my topic page is there a way I can perform an if statement somewhere on the lines of the below

*Viewing my topic page which is named "Printing Overview"*


@if (Model.SystemName.Equals(name_of_JCarousel_in_topic_after_content_widgetZone, StringComparison.CurrentCultureIgnoreCase))
{
    @await Component.InvokeAsync("Widget", new { widgetZone = "topic_after_content" })
}



I only ask this as currently if I want to have different JCarousels on different Topic pages I'm having to create new custom widget zones every-time which isn't ideal.

Any suggestions would be most welcome.

Thanks



Hello again, jslater,

It is not possible to do such check since the ViewComponent will return an HTML string that contains all JCarousels mapped to that widget-zone. Such code should be written in the ViewComponent itself rather than in the View. The back-end code is closed for customization though.

I suggest you try the approach with the different widget-zones for the different carousels, which is surely not ideal, but I think is safer and easier. Every other solution would require a lot more custom work which we can do for you if you are interested.

Kind regards,
Valentin
5 лет назад
Thanks! I'll stick with the different widget zones for now then.

Cheers
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.