Orchard CMS custom widget view

2019-09-07 13:15发布

I'm writing module for Orchard CMS, and I need to display elements of my content type in widget.

Drivers/FilesWidgetDriver.cs:

public class FilesWidgetPartDriver : ContentPartDriver<FilesWidgetPart>
{
    private readonly IFileService _fileService;

    public FilesWidgetPartDriver(IFileService fileService)
    {
        _fileService = fileService;
    }

    protected override DriverResult Display(FilesWidgetPart part, string displayType, dynamic shapeHelper)
    {
        return ContentShape("Parts_FilesWidget", () => shapeHelper.Parts_FilesWidget(
            Files: _fileService.GetFiles()
        ));
    }
}

Models/FilesWidget.cs

public class FilesWidgetPart : ContentPart
{
}

Views/Parts/FilesWidget.cshtml

@using ModuleName.Models
@using Orchard.ContentManagement
@{
    var files = (IContentQuery<FilePart>)Model.Files;
}
<div>
@foreach (var file in files)
{
    @Html.ActionLink(file.FileName, "GetFile", "FileAdmin");
}
</div>

Migrations.cs

public int UpdateFrom1()
{
    ContentDefinitionManager.AlterTypeDefinition("FilesWidget", type => type
       .WithPart("FilesWidgetPart")
       .WithPart("WidgetPart")
       .WithSetting("Stereotype", "Widget")
    );
    return 2;
}

public int UpdateFrom2()
{
    ContentDefinitionManager.AlterTypeDefinition("FilesWidget", type => type
        .WithPart("CommonPart")
    );
return 3;
}

But when I add widget to page, it's empty. What's wrong? Thank you!

1条回答
混吃等死
2楼-- · 2019-09-07 14:06

You're probably missing placement.

查看更多
登录 后发表回答