【问题标题】:Umbraco 8 - How to render two different JS Bundles using ClientDependency - RenderJsHere()Umbraco 8 - 如何使用 ClientDependency 渲染两个不同的 JS 包 - RenderJsHere()
【发布时间】:2021-02-09 20:46:59
【问题描述】:

我想使用 RenderJsHere() 渲染两个不同的 javascript 文件包。

我已将它放在页面上的两个不同位置,但它在两个位置都显示了所有文件(第 1 组 + 第 2 组文件)。谁能指导我如何使用 RenderJsHere() 渲染两组不同的文件?

下面是一些示例代码。

谢谢,

@inherits Umbraco.Web.Mvc.UmbracoViewPage
@using ClientDependency.Core.Mvc
<!DOCTYPE html>
<html>
<head>                        
    @Html.RenderCssHere()

     @{
        Html.RequiresJs("~/content/js/jquery-3.5.1.js", 1);        
     }
    @Html.RenderJsHere() ===========  **1st group of files in header**

</head>
<body>
    Some HTML here

    Bottom of page

    @{
        Html.RequiresJs("~/content/js/bootstrap.js", 1);
        Html.RequiresJs("~/content/js/jquery.lazy.js", 2);
        Html.RequiresJs("~/content/js/slick.js", 3);
        Html.RequiresJs("~/content/js/app.js", 4);
        Html.RequiresJs("~/content/js/myjs.js", 5);
    }
    @Html.RenderJsHere() **2nd group of files at last in page**

</body>
</html>

【问题讨论】:

    标签: umbraco client-dependency


    【解决方案1】:

    在此处查看您是如何创建命名包的:ClientDependency in umbraco doesn't include my bundles - 然后您可以在任何地方渲染单个包。

    【讨论】:

      【解决方案2】:

      您可以使用RequiresJsBundle 来设置您要使用的命名包。然后使用RenderJsHere

      Html.RequiresJsBundle("customjs1"); 
      @Html.RenderJsHere()
      

      https://github.com/Shazwazza/ClientDependency/blob/b5ba8cf6fbe476365b948888478e4389dbd0f710/ClientDependency.Mvc/HtmlHelperExtensions.cs

      【讨论】:

        猜你喜欢
        • 2017-02-01
        • 1970-01-01
        • 1970-01-01
        • 2011-10-16
        • 2012-02-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多