Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
#1 2014-06-17 04:45:46
- gomedia
- Plugin Author
- Registered: 2008-06-01
- Posts: 1,373
adi_list - Use lists like arrays
Summary
This plugin gives you a way of defining a list and using it like an array:
- access any element according to its index
- step through the list, one at a time
- automatically repeat the list
The key thing to remember here is that adi_list doesn’t do the iterative looping.
You can use the list in isolation to pluck out values, or perhaps more usefully in conjunction with some external looping process – such as <txp:article />
or <txp:images />
.
See the help supplied with the plugin, or have a look online. You can download the latest version from here.
Examples
For example, you might set up a list:
<txp:adi_list name="mylist" value="tom,dick,harry,george" />
Access items directly:
<txp:adi_list_item name="mylist" index="2" />
- will return harry
<txp:adi_list_last name="mylist" />
- returns george
To step through the list:
<txp:adi_list_next name="mylist" />
- returns dick (the pointer is initialised to the first item)
<txp:adi_list_end name="mylist" />
- shifts the pointer to the end of the list, without outputting anything
Manipulating the list:
<txp:adi_list name="mylist" value="tom,dick,harry,george" repeat="1" />
- sets up a repeating list (i.e. tom,dick,harry,george,tom,dick,harry,george,tom,dick,harry,george …)
<txp:adi_list name="mylist" value="tom,dick,harry,george" random="1" />
- randomises the list
A more complicated scenario
To do something a bit more sexy, chuck another list into the mix. Here I’m using <rah_repeat />
to drive the loop, but in practice you’d probably use <txp:article />
or some such:
<txp:adi_list name="blocksize" value="2,2,1,1,2,1,1,2" repeat="1" />
<txp:adi_list name="orientation" value="h,v,v,h" repeat="1" />
<txp:rah_repeat value="1,2,3,4,5,6,7,8,9,10,11,12" wraptag="ol" break="li">
<txp:adi_list_item name="blocksize" />
<txp:adi_if_list name="blocksize" value="2">
<txp:adi_list_item name="orientation" />
<txp:adi_list_next name="orientation" />
</txp:adi_if_list>
<txp:adi_list_next name="blocksize" />
</txp:rah_repeat>
The output is:
1. 2 h 2. 2 v 3. 1 4. 1 5. 2 v 6. 1 7. 1 8. 2 h 9. 2 h 10. 2 v 11. 1 12. 1
- which looks a bit random, but picture it as the basic information to set out a modular grid:
+---------+----+ | 1 | | +----+----+ 2 | | 3 | 4 | | +----+----+----+ | | 6 | 7 | | 5 +----+----+ | | 8 | +----+----+----+ | 9 | | +----+----+ 10 | | 11 | 12 | | +----+----+----+
Requirements
No special requirements.
Version history
- 0.2
- TXP 4.6 tag registration
- 0.1
- initial release
Feedback
Comments are most welcome.
Developers’ benefit society
If you find this plugin useful, please consider donating to the Textpattern development team.
Last edited by gomedia (2015-06-17 12:48:52)
Offline
#2 2015-06-17 12:49:47
- gomedia
- Plugin Author
- Registered: 2008-06-01
- Posts: 1,373
Re: adi_list - Use lists like arrays
Version 0.2 available for download – only TXP 4.6 tag registration.
Offline
Pages: 1