Update a field of a content entry in Locomotivecms

119 Views Asked by At

In Locomotivecms,I created a content type called "posts" with a field called "views" which is integer. The field "views" are supposed to add 1 incrementally every time the content entry page was visited. I try {% assign post.views = post.views +1 %} in liquid ,but that didn't make sense. Is there any liquid tag to carry it out ?

2

There are 2 best solutions below

0
Victor On

You may want to try {% increment post.views %}

0
Drakes On

You can increment in Locomotive CMS this way:

{% assign counter = 0 %}
{% capture counter %}{{ counter | plus: 1 }}{% endcapture %}