Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我在一个名为“权重”的频道中有一个字段,用户可以在其中设置一个介于 0-1000 之间的数字。在页面加载时,我想为每个输入生成一个介于 0 和“权重”之间的随机数,然后根据这些数字对输入进行排序。
我如何使用 Craft 2/Twig 做到这一点?
创建随机数:
{% set range = range(1, weight) %} {% set numbers= random(range) %} Random No: {{ numbers }}