コード例 #1
0
        public async ValueTask <FluidValue> ProcessAsync(FluidValue input, FilterArguments arguments, LiquidTemplateContext ctx)
        {
            string listContentItemId;

            if (input.Type == FluidValues.Object && input.ToObjectValue() is ContentItem contentItem)
            {
                listContentItemId = contentItem.ContentItemId;
            }
            else
            {
                listContentItemId = input.ToStringValue();
            }

            var listItems = await ListQueryHelpers.QueryListItemsAsync(_session, listContentItemId);

            return(FluidValue.Create(listItems, ctx.Options));
        }
コード例 #2
0
        public async ValueTask <FluidValue> ProcessAsync(FluidValue input, FilterArguments arguments, TemplateContext ctx)
        {
            if (!ctx.AmbientValues.TryGetValue("Services", out var services))
            {
                throw new ArgumentException("Services missing while invoking 'list_items'");
            }

            string listContentItemId = null;

            if (input.Type == FluidValues.Object && input.ToObjectValue() is ContentItem contentItem)
            {
                listContentItemId = contentItem.ContentItemId;
            }
            else
            {
                listContentItemId = input.ToStringValue();
            }

            var session = ((IServiceProvider)services).GetRequiredService <ISession>();

            var listItems = await ListQueryHelpers.QueryListItemsAsync(session, listContentItemId);

            return(FluidValue.Create(listItems));
        }
コード例 #3
0
    /// <summary>
    /// Returns list items.
    /// </summary>
    /// <param name="listContentItemId">The list content item id.</param>
    /// <param name="itemPredicate">The optional predicate applied to each item. By defult published items only.</param>
    /// <returns>An enumerable of list items satisfying given predicate.</returns>
    public static async Task <IEnumerable <ContentItem> > QueryListItemsAsync(this IOrchardHelper orchardHelper, string listContentItemId, Expression <Func <ContentItemIndex, bool> > itemPredicate = null)
    {
        var session = orchardHelper.HttpContext.RequestServices.GetService <ISession>();

        return(await ListQueryHelpers.QueryListItemsAsync(session, listContentItemId, itemPredicate));
    }