What would really be helpful to developers is to have an extension method that is part of the main nopCommerce solution that can be reference. This could make it much easier in the plugins, improve reusability, and make upgrading easier, similar to how the RegisterPluginDataContext simplified the data context registration in the plugins.
Below is an extension method I use in my plugins, for version 4.0.
This is working well for me, and helps simplify the calling code.
Unfortunately I still have to copy this into every plugin that needs it, and if the core code changes, this may also have to change in every plugin where it is used. Can the NOP team just add this into the main solution, then every plugin can just reference it?
public static HtmlString TabContent(this AdminTabStripCreated eventMessage, string tabId, string tabName, string url)
{
return new HtmlString($@"
<script type='text/javascript'>
$(document).ready(function() {{
$(`<li><a data-tab-name='{tabId}' data-toggle='tab' href='#{tabId}'>{tabName}</a></li>
`).appendTo('#{eventMessage.TabStripName} .nav-tabs:first');
$.get('{url}', function(result) {{
$(`<div class='tab-pane' id='{tabId}'>` + result + `</div>`).appendTo('#{eventMessage.TabStripName} .tab-content:first');
}});
}});
</script>");
}
Example of calling the above extension function from HandleEvent:
public void HandleEvent(AdminTabStripCreated eventMessage)
{
if (eventMessage?.Helper == null)
return;
if (eventMessage.TabStripName == "vendor-edit")
{
string url = new UrlHelper(//... url helper logic here as you need
var vendorTab = eventMessage.TabContent("MyTabId", "My Tab Name", url);
eventMessage.BlocksToRender.Add(vendorTab);
}
}
As you can see, the "eventMessage.TabContent" neatly generates the needed tab content for the calling function.