【问题标题】:Macro inside another macro另一个宏中的宏
【发布时间】:2021-10-24 14:11:14
【问题描述】:

我正在尝试将宏放入另一个宏中, 我从 Umbraco 收到错误消息(完全来自我放置 RenderMacro 的行):

发生错误 当前没有 PublishedContentRequest 时无法呈现宏。 异常详情 System.InvalidOperationException:当没有当前的 PublishedContentRequest 时无法呈现宏。

问题:在另一个宏中渲染宏需要做什么?

这是 CTAMacro 代码的重要部分,其中包含调用“StartPracticingButton”的 RenderMacro:

@using System.Text.RegularExpressions;
@using System.Configuration;

@inherits Umbraco.Web.Macros.PartialViewMacroPage
 @{
string CTATitle = (string)Model.MacroParameters["ctaTitle"];
string CTAContent = (string)Model.MacroParameters["ctaContent"];
string CTATestId = (string)Model.MacroParameters["ctaTestId"];
string fullProductButtonText = "";
string fullProductSku = "";
   } 
 <div class="ctaFreeTest">
    <div class="cta">
        <div class="ctaTitle">
            @CTATitle
        </div>
        {
          <div class="productPageButtonContainer">

////////////////////////////出现错误的 RENDERMACRO

       @Umbraco.RenderMacro("StartPracticingButton", new 
    ViewDataDictionary { { "nodeid", Model.Content.Id } })
    </div>
        }

    </div>
    

</div>

【问题讨论】:

  • 您使用的是哪个版本的 Umbraco?对于 CTA 之类的东西,有比使用宏更好的选择。据我所知,宏中的宏从未起作用。你不能只使用局部视图来代替“内部”宏吗?
  • 7.X.X 好的,所以你说我需要将 CTAmacro 替换为局部视图并在局部内部以实现另一个宏?

标签: umbraco


【解决方案1】:

您可能完全不使用宏,但至少我会用局部视图替换宏内的宏(“StartPracticingButton”)。我认为这应该可以解决它,而不会改变您使用 CTMacro 的方式。

作为奖励,从 UmbracoViewPage 继承的局部视图应该已经具有 Umbraco 上下文,因此您不必传递节点 ID。您可以直接在局部视图中使用 Model.Content.Id。

所以

Html.RenderPartial("StartPracticingButton")

如果您将 StartPracticingButton 文件从 Views/MacroPartials 移动到 Views/Partials,应该这样做吗?

【讨论】:

    猜你喜欢
    • 2023-03-07
    • 2013-06-13
    • 1970-01-01
    • 1970-01-01
    • 2015-07-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多