Published on 11/25/2020
Published by Praveen Gupta
Loops samples (for loop, loop on db results variable)
For loop: You can use this as normal for loop like we using in PHP or JS
1 2 3 4 |
for(i=1; i<=10; i++) { console.log(i); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
Ex_1: [loop.@eachIndex start=1 step=1 stop=10 ] [aw2.get @eachIndex dump=true /] [aw2.get @eachIndex.item /] [aw2.get @eachIndex.count /] [/loop.@eachIndex] Ex_2: [loop.@ec start="1" step="1" stop="12"] [php.mktime p1="0" p2="0" p3="0" p4="{@ec.item}" p5="10" set="time" /] [php.date p1="F" p2="{time}" set="template.month_name" /] [php.strtolower p1="{template.month_name}" set="template.lowercase_month" /] [aw2.get template.month_name set="template.months.{template.lowercase_month}" /] [/loop.@ec] [template.return template.months /] |
Take a look in below image and check dump and use various values from counter as per your requirements.
Database query result loop:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
[arr.create set="module.db_params"] [post_type]event[/post_type] [posts_per_page]12[/posts_per_page] [/arr.create] [db.post-builder.get_data args="{module.db_params}" set="template.result" /] Query: [template.get result.request /] Found post count: [template.get result.post_count /] [loop.@eachPost template.result.posts] Post ID: [aw2.get @eachPost.item.ID dump=t /] Post Title: [aw2.get @eachPost.item.post_title dump=t /] Post meta: [aw2.get @eachPost.item.meta dump=t /] Post meta edit_last: [aw2.get @eachPost.item.meta._edit_last dump=t /] [/loop.@eachPost] |
If you Getting array as a object, please check below code
1 2 3 4 5 6 7 8 9 |
[aw2.get woodata.related_products set="template.related_products"/] [template.related_products dump=1/] [loop.@related template.related_products] [aw2.get @related.item set="template.product"/] [template.get product json_encode=true set="template.d" /] [template.get d json_decode=true set="template.d2" /] [template.get d2 dump=t /] [/loop.@related] |