Hello!
Where can I find documentation, if it exists, to mount a metronic template in an existing blazor application created with visual studio?
I'm working in Visual Studio 2019 Community edition.
My steps have been:
1. Download the demo5
2. Copy assets folder into wwwroot
3. Splitting the theme into different Blazor pages
a. _Host.cshtml contains
body
<component type="typeof(App)" render-mode="ServerPrerendered" />
javascripts
b. MainLayout.razor contains anything else
Main
Root
Drawers
Toolbar
Modals
Apparently it does work, but, in example, clicking over the user's avatar the dropdown menu does not work.
Any suggestion, doc, video?
Thank you!
Hi,
Your integration steps look fine, you can find our Metronic 8 Blazor Server integration doc here: https://preview.keenthemes.com/metronic8/demo1/documentation/getting-started/integration/blazor.html
I'm talking about blazor server integration.
Thank you for the link.
I followed those steps one by one.
My point is that when Blazor starts the Metronic scripts do not work.
I tried different approaches as well, like stopping Blazor autostart script
<script src="_framework/blazor.server.js" autostart="false"></script>
<script>
Blazor.start().then(function () {
var customScript = document.createElement("script");
customScript.setAttribute("src", "assets/plugins/global/plugins.bundle.js");
document.body.appendChild(customScript);
var anotherScript = document.createElement("script");
anotherScript.setAttribute("src", "assets/js/scripts.bundle.js");
document.body.appendChild(anotherScript);
});
</script>
Since I'm compiling the server using visual studio, shall I skip the webpack script compilation?
I was missing that point, since the site is working when blazor scripts are not loaded.
Do only menu components doesn't work?
Could you please show all scripts which you are connecting in Pages/_Layout.cshtml?
In the new model the page name is Pages/_Host.cshtml but I guess this does not matter.
<!--begin::Body-->
<body class="header-fixed header-tablet-and-mobile-fixed toolbar-enabled toolbar-fixed aside-enabled aside-fixed" >
<component type="typeof(App)" render-mode="ServerPrerendered" />
<div>
<environment include="Staging,Production">
An error has occurred. This application may no longer respond until reloaded.
</environment>
<environment include="Development">
An unhandled exception has occurred. See browser dev tools for details.
</environment>
<a href="%22%20class=%22reload" target="_blank" rel="noopener noreferrer">Reload</a>
<a class="dismiss">🗙</a>
</div>
<!--begin::Javascript-->
<script>var hostUrl = "assets/";</script>
<!--begin::Global Javascript Bundle(used by all pages)-->
<script src="assets/plugins/global/plugins.bundle.js"></script>
<script src="assets/js/scripts.bundle.js"></script>
<!--end::Global Javascript Bundle-->
<!--begin::Page Vendors Javascript(used by this page)-->
<script src="assets/plugins/custom/fullcalendar/fullcalendar.bundle.js"></script>
<script src="assets/plugins/custom/datatables/datatables.bundle.js"></script>
<!--end::Page Vendors Javascript-->
<!--begin::Page Custom Javascript(used by this page)-->
<script src="assets/js/widgets.bundle.js"></script>
<script src="assets/js/custom/widgets.js"></script>
<script src="assets/js/custom/apps/chat/chat.js"></script>
<script src="assets/js/custom/utilities/modals/upgrade-plan.js"></script>
<script src="assets/js/custom/utilities/modals/create-app.js"></script>
<script src="assets/js/custom/utilities/modals/users-search.js"></script>
<!--end::Page Custom Javascript-->
<script src="_framework/blazor.server.js"></script>
<!--end::Javascript-->
</body>
<!--end::Body-->
I checked some demo 1 homepage feature and it does not work:
1) Remove theme script tags from this file, leave only a blazor.server.js script.
<script src="_framework/blazor.server.js"></script>
I did, but with no luck (I know it's confusing, sorry, it was my 3rd post).
Now at the end of MainLayout.razor I've
@inject IJSRuntime JS
@inject NavigationManager MyNavigationManager
@code {
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
await JS.InvokeAsync<IJSObjectReference>("import", MyNavigationManager.ToAbsoluteUri("assets/plugins/global/plugins.bundle.js"));
await JS.InvokeAsync<IJSObjectReference>("import", MyNavigationManager.ToAbsoluteUri("assets/js/scripts.bundle.js"));
await JS.InvokeAsync<IJSObjectReference>("import", MyNavigationManager.ToAbsoluteUri("assets/plugins/custom/fullcalendar/fullcalendar.bundle.js"));
await JS.InvokeAsync<IJSObjectReference>("import", MyNavigationManager.ToAbsoluteUri("assets/plugins/custom/datatables/datatables.bundle.js"));
await JS.InvokeAsync<IJSObjectReference>("import", MyNavigationManager.ToAbsoluteUri("assets/js/widgets.bundle.js"));
await JS.InvokeAsync<IJSObjectReference>("import", MyNavigationManager.ToAbsoluteUri("assets/js/custom/widgets.js"));
await JS.InvokeAsync<IJSObjectReference>("import", MyNavigationManager.ToAbsoluteUri("assets/js/custom/apps/chat/chat.js"));
await JS.InvokeAsync<IJSObjectReference>("import", MyNavigationManager.ToAbsoluteUri("assets/js/custom/utilities/modals/upgrade-plan.js"));
await JS.InvokeAsync<IJSObjectReference>("import", MyNavigationManager.ToAbsoluteUri("assets/js/custom/utilities/modals/create-app.js"));
await JS.InvokeAsync<IJSObjectReference>("import", MyNavigationManager.ToAbsoluteUri("assets/js/custom/utilities/modals/users-search.js"));
}
}
}
function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.moment=t()}
In file MainLayout.razor in function OnAfterRenderAsync please load only two files listed below.
assets/plugins/global/plugins.bundle.js
assets/js/scripts.bundle.js
Thank you! I confirm I get all working after compiling using webpack!
Glat to hear that All the best with your project!
I also tried to import the main theme dependencies inside /Shared/MainLayout.razor in OnAfterRenderAsync lifecycle hook.
And commenting both scripts in _Host.cshtml
@inject IJSRuntime JS
@inject NavigationManager MyNavigationManager
@code {
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
await JS.InvokeAsync<IJSObjectReference>("import", MyNavigationManager.ToAbsoluteUri("assets/plugins/global/plugins.bundle.js"));
await JS.InvokeAsync<IJSObjectReference>("import", MyNavigationManager.ToAbsoluteUri("assets/js/scripts.bundle.js"));
}
}
}
Could you please specify which integration you are trying to achieve, Blazor Server or Blazor Webassembly?
I noticed that removing this line
<script src="_framework/blazor.server.js"></script>