Web development Birmingham

Modx Extra - csvToTpl

By Andrew Ward By Andrew Ward Oct 28, 2014 web development

If you use modx then here is a handy little extra for you. This simple module allows you to take a csv string and output it iteratively within a tpl.

DOWNLOAD csvToTpl v1.0.1

Simple usage:

[ [!csvToTpl? &csv=`my, text, csv` &tpl=`myTpl.tpl`]]

Use a different tpl for a certain item:

[ [!csvToTpl? &csv=`my, text, csv` &tpl=`myTpl.tpl` &tpl_3=`myTpl3.tpl`]]

note: the first tpl is &tpl_0

tpl variables:

  • [ [+item]] = the item in the CSV array.
  • [ [+itemUCFirst]] = the csv item with the first letter capitalised.
  • [ [+itemUCWords]] = the csv item with the first letter of all words within it capitalised.
  • [ [+itemCaps]] = the csv item with all letters capitalised.
  • [ [+itemClass]] = the csv item made lowercase and all non-alphanumeric characters replaced with a hyphen (-).

Example TPL

normal: [ [+item]]<br />
ucfirst: [ [+itemUCFirst]]<br />
ucwords: [ [+itemUCWords]]<br />
caps: [ [+itemCaps]] <br />
class friendly: [ [+itemClass]]

Did you find this article useful? Sharing is a great way to show support, and ensures that we can continue to create more quality articles:

Get a free quote