2016-03-04 66 views
1

我有一个包含页眉和页脚信息的主布局。另外,我有使用特定渲染项目和主布局的页面。如果使用特定渲染项目的页面呈现,则应将主布局中的标题从默认标题值更改。Sitecore检查渲染项目是否初始化

这是我的伪代码。

namespace renderingItem1  

public override void Initialize(Rendering rendering) 
{ 
    //code here 
} 

public string anotherMethod() 
{ 
    string str = ""; 
    if (Initialized == true) { 
     str = "Rendering Item is called in this page"; 
    } 
    return str; 
} 


// In another project, added 'renderingItem1.dll' into references in abother project 
// this is masterLayout.cshtml 

@using renderingItem1 

@string pageTitle = ""; 
@if (redneringItem1.anotherMethod() is NOT empty) { 

    pageTitle = redneringItem1.anotherMethod(); 
} 

在masterLayout.cshtml,它总是输出是str = ""

+0

你应该发布你想实现的内容。我不知道你的代码应该做什么。 –

+0

在@Marek会回复你第二个问题后,你会在这篇文章中添加更多的问题吗? :D –

+0

@SitecoreClimber和Marek,我更新了,请让我知道你是否需要更多信息。 – Jay

回答

1

默认在Initialize添加Initialized属性类,并将其设置为true:

public bool Initialized { get; set; } 

public override void Initialize(Rendering rendering) 
{ 
    Initialized = true; 
    ... 
} 

顺便说一句,您的anotherMethod不能是静态的 - 如果它是静态的,则不能访问非静态Initialized属性,并且您将无法检测当前实例的状态是什么你的渲染。

+0

谢谢,我添加了另一个代码。可能吗?? – Jay