如果Sitecore中没有内容项,如何在模板中呈现模板

时间:2016-03-14 13:18:50

标签: asp.net sitecore sitecore8

这似乎是一个非常简单的概念,但我无法解决。我尝试做的是,向页面呈现/显示模板的标准值 创造了物品&使用Rocks的模板。这是结构。

1。 Sublayout - footer.ascx

private bool IfTextBoxEmpty(string text, string message, Control control)
    {
        if (text == "")
        {
            MessageBox.Show(message);
            this.ActiveControl = control;
            return true;
        }
        return false;
    }

2。 Sublayout - StickyNav.ascx

if (!IfTextBoxEmpty(ClientAddressTextBox.Text, "Please Enter Client Address", ClientAddressTextBox)
{
            //if not - Do Something
}

第3。模板 - 粘性导航
enter image description here
enter image description here

第一张照片是模板&第二个显示_Standard Values中指定的默认值 然后,在Sitecore Explorer中,
<div class="content"> <h1>This is a title.</h1> <p>All the content goes here</p> <sc:placeholder runat="server" Key="footercontent" /> </div>
enter image description here
现在,有一个内容项&#34;索引&#34;在/ sitecore / content /下。它声明了这些布局: enter image description here
当我右键单击<a class="btn" href="#"> <sc:Text Field="Sticky Nav Title" runat="server" /> </a> 时,索引页面会打开,并且还会显示页脚内容。

但是,我无法看到文本&#39; Go To Top&#39;,它被设置为标准值(图2)。它是空的。

我在这里缺少什么。

2 个答案:

答案 0 :(得分:1)

可能有一些因素阻碍了所显示的内容。对于前端,最好的办法是排除发布之类的事情 - 即确保模板,字段,标准值和内容项都正确发布。如果您处于预览状态,这可能不太重要,但在部署时值得注意

sc:Text控件呈现时,将运行renderField管道。在相互作用的时候,它将通过api与Sitecore交谈。

通过后面的代码检查控件(假设由于runat =“server”标签,它是ascx)。检查:

Field field = Sitecore.Context.Item.Fields["Sticky Nav Title"];

if (field != null)
{
    string value = field.Value;
}

通过调试来检查字段实际上是否具有您需要的值。

在cms中,当您查看感兴趣的页面时,“Sticky Nav Title”字段似乎有一个值,并且是您感兴趣的值吗?

答案 1 :(得分:0)

我意识到最初的想法本身就是一个错误。如果必须在页面上显示它的值,则必须是项目。

因此,我使用模板List<Trees> list = new ArrayList<Trees>(); // now no type Casting Needed. Trees objToRemove = list.get(number); // This code will Work Fine if You use a Type-Safe ArrayList. /sitecore/content/Sticky Nav Button下创建了一个新项目。

在StickyNav.ascx中,将控件更新为:

Sticky Nav

希望这有助于像我这样的初学者。