Composite C1 - 在剃刀函数中访问全局数据类型

时间:2014-02-03 22:12:09

标签: c# asp.net razor c1-cms

我一直在尝试实现在复合c1站点中显示全局数据类型的函数。

我理解基本的剃刀功能如何工作,但他们似乎只使用本地数据。我期待创建一个剃刀函数,访问和过滤(以类似于可视化函数可用的DataReferenceFilter的方式)我为员工BIOS创建的全局数据类型,以便我可以在整个站点的多个页面上显示此信息。

我已经能够创建一个实现此功能的视觉功能,但这些功能与手动编辑的风格不相称。

这是使用本地数据直接输入函数的函数布局:

@inherits RazorFunction

    @functions {
        public override string FunctionDescription
        {
            get  { return "A people widget that diaplays a picture, name and small bio of a team member"; }
        }

    [FunctionParameter(Label = "Name", Help = "Input the persons name here", DefaultValue = "Firstname Lastname")]
    public string Name { get; set; }

    [FunctionParameter(Label = "Position", Help = "Input the persons position here", DefaultValue = "Manager")]
    public string Position { get; set; }

    [FunctionParameter(Label = "Qualifications", Help = "Input the persons qualifications here",DefaultValue = "University of Newcastle")]
    public string Qualifications { get; set; }

    [FunctionParameter(Label = "Bio", Help = "Input the persons biography snippit here", DefaultValue = "Input bio snippit here")]
    public string Bio { get; set; }

    [FunctionParameter(Label = "Image", Help = "Select the image to be used by this people widget")]
    public DataReference<IMediaFile> ImageSource { get; set; }
}

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://www.composite.net/ns/function/1.0">
    <head>
    </head>
    <body>
        <div class="peoplebox">
            <div class="peopleimg">
                <img src="~/media({@ImageSource.Data.Id})" alt="..." />
            </div>
            <p class="peoplename">@Name</p>
            <p><i>@Position</i></p>
            <h5>@Qualifications</h5>
            <div class="blockquote">
                <p>@Bio</p>
            </div>
        </div>
    </body>
</html>

The page似乎指向正确的方向,但我不确定如何将其整合到剃刀功能中。

1 个答案:

答案 0 :(得分:1)

您可以在Razor函数中使用Data属性。一个小例子就是这样的

@{
    var employees = Data.Get<INameOfYouDataType>().Where(m => ... some filter);

    foreach (var employee in employees)
    {
        <div class="peopleimg">
            <img src="~/media({@employee.Id})" alt="..." />
        </div>
        <p class="peoplename">@employee.Name</p>
        <p><i>@employee.Position</i></p>
        <h5>@employee.Qualifications</h5>
        <div class="blockquote">
            <p>@employee.Bio</p>
        </div>    
    }