查询中只有一张图像

时间:2019-01-30 15:37:17

标签: octobercms octobercms-plugins

我从十月厘米开始编码。

我已经做过乐透了,但是我遇到了一个我没有解决的问题。

也许有人也可以使用Mall插件吗?

我使用此代码在octobercms系统中显示图像集合。 我使用了Mall插件,但只想要第一张照片。

我该怎么做?

{% partial __SELF__ ~ '::images' images=item.all_images %}''

这就是我已经绷紧的东西

{% partial __SELF__ ~ '::images' images=item.first%}
 {% partial __SELF__ ~ '::images' images=item.image[0]%}
    {{ item.brand_id }}<br />
    {{ item.stock }}<br />
    {{ item.category_id }}<br />    

这是查询结果的一部分

"image_sets":
[
    {
        "id":"12",
        "name":"fotos",
        "product_id":"13",
        "is_main_set":"1",
        "created_at":"2019-01-30 11:06:15",
        "updated_at":"2019-01-30 11:06:15",

        "images":
    [
        {
            "id":"48",
            "disk_name":"5c518522d3c97203253589.jpg",
            "file_name":"Oudenland-OU-160_actie-e1546246010172.jpg",
            "file_size":"236653","content_type":"image\/jpeg",
            "title":null,
            "description":null,
            "field":"images",
            "sort_order":"1",
            "created_at":"2019-01-30 11:06:10",
            "updated_at":"2019-01-30 11:06:15","path":"https:\/\/www.oudenland.nl\/new\/storage\/app\/uploads\/public\/5c5\/185\/22d\/5c518522d3c97203253589.jpg",
            "extension":"jpg"},{"id":"46",
            "disk_name":"5c5185221e860640905785.jpg",
            "file_name":"lastang-160.jpg",
            "file_size":"348989",
            "content_type":"image\/jpeg",
            "title":null,
            "description":null,
            "field":"images",
            "sort_order":"2",
            "created_at":"2019-01-30 11:06:10",
            "updated_at":"2019-01-30 11:06:15",
            "path":"https:\/\/www.oudenland.nl\/new\/storage\/app\/uploads\/public\/5c5\/185\/221\/5c5185221e860640905785.jpg",
            "extension":"jpg"},{"id":"45",
            "disk_name":"5c5185221df2c249730093.png",
            "file_name":"Oudenland_metal_clamp.png",
            "file_size":"1087142","content_type":"image\/png",
            "title":null,"description":null,
            "field":"images",
            "sort_order":"3","created_at":"2019-01-30 11:06:10",
            "updated_at":"2019-01-30 11:06:15","path":"https:\/\/www.oudenland.nl\/new\/storage\/app\/uploads\/public\/5c5\/185\/221\/5c5185221df2c249730093.png",
            "extension":"png"},{"id":"47",
            "disk_name":"5c518522c3d05464273058.png",
            "file_name":"Oudenland-CA-160_side.png",
            "file_size":"699668",
            "content_type":"image\/png","title":null,
            "description":null,
            "field":"images",
            "sort_order":"4",
            "created_at":"2019-01-30 11:06:10",
            "updated_at":"2019-01-30 11:06:15",
            "path":"https:\/\/www.oudenland.nl\/new\/storage\/app\/uploads\/public\/5c5\/185\/22c\/5c518522c3d05464273058.png",
            "extension":"png"
        },

        {
            "id":"49",
            "disk_name":"5c51852377318670458855.png",
            "file_name":"Oudenland-OU-160_front.png",
            "file_size":"822471","content_type":"image\/png",
            "title":null,
            "description":null,
            "field":"images",
            "sort_order":"5",
            "created_at":"2019-01-30 11:06:11",
            "updated_at":"2019-01-30 11:06:15",
            "path":"https:\/\/www.oudenland.nl\/new\/storage\/app\/uploads\/public\/5c5\/185\/237\/5c51852377318670458855.png",
            "extension":"png"
        },
        {
            "id":"50",
            "disk_name":"5c518523bbb54916275956.png",
            "file_name":"Oudenland-OU-160_strap.png",
            "file_size":"1074603",
            "content_type":"image\/png",
            "title":null,"description":null,"field":"images",
            "sort_order":"6",
            "created_at":"2019-01-30 11:06:11","updated_at":"2019-01-30 11:06:15",
            "path":"https:\/\/www.oudenland.nl\/new\/storage\/app\/uploads\/public\/5c5\/185\/23b\/5c518523bbb54916275956.png",
            "extension":"png"
        }
    ]
    }
]

    ,"prices":
    [
        {
            "id":"16",
            "price":"11500",
            "product_id":"13",
            "variant_id":null,"currency_id":"2",
            "created_at":"2019-01-30 11:03:43",
            "updated_at":"2019-01-30 11:03:43",
            "currency":{"id":"2",
            "code":"EUR",
            "symbol":"\u20ac",
            "rate":1,"decimals":"2",
            "format":"{{ currency.symbol }} {{ price|number_format(2 \".\", \"'\") }}",
            "sort_order":"2",
            "is_default":false,
            "created_at":"2019-01-25 09:51:42",
            "updated_at":"2019-01-25 13:44:57"}}],
            "variants":[],"downloads":[],"taxes":[{"id":"1",
            "name":"BTW","percentage":"21.00",
            "created_at":"2019-01-25 09:51:42",
            "updated_at":"2019-01-25 13:45:09",
            "pivot":{"product_id":"13",
            ,"tax_id":"1"}}],
            "additional_prices":[]
            }

            {
                "id":13,"category_id":"5",
                "brand_id":"1",
                "user_defined_id":"OU-160",
                "name":"Lasinverter OU-160",
"image_sets":

[
    {"id":"12","name":"fotos",
            "product_id":"13",
            "is_main_set":"1",
            "created_at":"2019-01-30 11:06:15",
            "updated_at":"2019-01-30 11:06:15",
            "images":
        [   
            {"id":"48",
            "disk_name":"5c518522d3c97203253589.jpg",
            "file_name":"Oudenland-OU-160_actie-e1546246010172.jpg",
            "file_size":"236653",
            "content_type":"image\/jpeg",
            "title":null,
            "description":null,
            "field":"images",
            "sort_order":"1",
            "created_at":"2019-01-30 11:06:10",
            "updated_at":"2019-01-30 11:06:15",
            "path":"https:\/\/www.oudenland.nl\/new\/storage\/app\/uploads\/public\/5c5\/185\/22d\/5c518522d3c97203253589.jpg","extension":"jpg"},

            {"id":"46",
            "disk_name":"5c5185221e860640905785.jpg",
            "file_name":"lastang-160.jpg",
            "file_size":"348989",
            "content_type":"image\/jpeg","title":null,"description":null,
            "field":"images","sort_order":"2",
            "created_at":"2019-01-30 11:06:10",
            "updated_at":"2019-01-30 11:06:15",
            "path":"https:\/\/www.oudenland.nl\/new\/storage\/app\/uploads\/public\/5c5\/185\/221\/5c5185221e860640905785.jpg",
            "extension":"jpg"},

            {"id":"45",
            "disk_name":"5c5185221df2c249730093.png",
            "file_name":"Oudenland_metal_clamp.png",
            "file_size":"1087142",
            "content_type":"image\/png",
            "title":null,
            "description":null,
            "field":"images",
            "sort_order":"3",
            "created_at":"2019-01-30 11:06:10",
            "updated_at":"2019-01-30 11:06:15",
            "path":"https:\/\/www.oudenland.nl\/new\/storage\/app\/uploads\/public\/5c5\/185\/221\/5c5185221df2c249730093.png",
            "extension":"png"},

            {"id":"47",
            "disk_name":"5c518522c3d05464273058.png",
            "file_name":"Oudenland-CA-160_side.png",
            "file_size":"699668",
            "content_type":"image\/png",
            "title":null,"description":null,
            "field":"images",
            "sort_order":"4",
            "created_at":"2019-01-30 11:06:10",
            "updated_at":"2019-01-30 11:06:15",
            "path":"https:\/\/www.oudenland.nl\/new\/storage\/app\/uploads\/public\/5c5\/185\/22c\/5c518522c3d05464273058.png",
            "extension":"png"},

            {"id":"49",
            "disk_name":"5c51852377318670458855.png",
            "file_name":"Oudenland-OU-160_front.png",
            "file_size":"822471",
            "content_type":"image\/png",
            "title":null,
            "description":null,
            "field":"images",
            "sort_order":"5",
            "created_at":"2019-01-30 11:06:11","updated_at":"2019-01-30 11:06:15",
            "path":"https:\/\/www.oudenland.nl\/new\/storage\/app\/uploads\/public\/5c5\/185\/237\/5c51852377318670458855.png",
            "extension":"png"},

            {"id":"50",
            "disk_name":"5c518523bbb54916275956.png",
            "file_name":"Oudenland-OU-160_strap.png",
            "file_size":"1074603",
            "content_type":"image\/png",
            "title":null,
            "description":null,
            "field":"images","sort_order":"6","created_at":"2019-01-30 11:06:11","updated_at":"2019-01-30 11:06:15",
            "path":"https:\/\/www.oudenland.nl\/new\/storage\/app\/uploads\/public\/5c5\/185\/23b\/5c518523bbb54916275956.png",
            "extension":"png"}
        ]
    }
],```

1 个答案:

答案 0 :(得分:0)

我只是通过这个oc-mall插件,发现他们使用了一个类来获取图像/图像属性。 您可以走这条路看看。

OFFLINE\Mall\Classes\Traits\Images

,并显示第一个图像。您可以像这样使用它。

<img src="{{ item.image.thumb('auto', 240) }}" alt="{{ item.name }}"/>

不客气!!!