从Liquid模板将变量传递给onClick函数

问题描述

这是一个液体模板。 “ item”变量(第2行)是一个对象,我想将其传递给“ onclick 函数以在js文件中使用。 但是,它仅适用于字符串或数字 有人可以帮忙吗?谢谢!

<div class="flex flex-wrap">
            {% for item in portfolios %}
                {% assign test = item %}
                <a class="cursor-pointer portfolio block relative overflow-hidden w-full mb-6 md:w-1/2 md:mb-0" onclick="togglegallery('{{ test | json}}')">
                    <div class="captain absolute w-full h-full text-white p-4 flex flex-col justify-center items-center z-10 bg-blue-600">
                        <h3>{{ item.name }}</h3>
                        <p class="mb-0">
                            {{ item.description }}
                        </p>
                    </div>
                    <div class="relative pb-2/3">
                        <img class="absolute w-full h-full object-cover object-center" src="{{ item.thumnail }}" alt=""/>
                    </div>
                </a>
            {% endfor %}
        </div>

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)