Coded something up in Couch in an interesting way? Have a snippet or shortcode to share? Post it here for the community to benefit.
32 posts Page 4 of 4
@couchclass, the round brackets only appear inside <cms:php> block, hence the source of the error is there.
Code: Select all
<cms:php>echo (rand(1,<cms:show k_total_count />));</cms:php>

If there is nothing inside <cms:capture> then the whole setting of the random number is not happening and error doesn't occur. As to why the error happens - Couch executes statements starting from the most inner (deeper) one. This one inside <cms:php> block executes the first - <cms:show k_total_count /> - and without my 'cms:each mod' mentioned in OP there is no such variable 'k_total_count ' available in the context of <cms:each>. So, before the php kicks in, the statement looks like rand(1, ) which is not correct. The php engine expected something after the comma, but as 'k_total_count' was empty/not present - there was nothing before the closing bracket --> fatal error happens.

If you are still with me, then let me tell you that this code was written long ago, when stock tag <cms:each> was not very powerful and I wrote a mod expanding its capabilities, adding 'k_total_count' among other improvements. You did not have that mod installed despite its mention in the OP as a musthave. Nowadays situation is very different, Couch has evolved further and adopted my mod among other things, so in stock Couch code the variable has appeared but it is now called differently (KK's preferred a different name) - k_total_items.

In short, don't use the old 'cms:each' mod, change variable name so the whole line looks like this -
Code: Select all
<cms:set random_number = "<cms:php>echo (rand(1,<cms:show k_total_items />));</cms:php>"/>

And you should see it immediately working again.

Of course, this whole code nowadays looks a bit messy, and I would have coded it differently, maybe with json. ;) But CouchCMS is very good at keeping the legacy code working, so I applaud that something from years ago still works fine.

Visit Midware » CHANGELOG on GitHub for the latest published documentation pages.
Check out my other pinned repositories: Tweakus-Dilectus » Addons and Cms-Fu » Functions.
Join CMS:COUCH telegram channel

Ready to work!
Thanks a million, Trendoman. Works perfectly.
32 posts Page 4 of 4
cron