We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 18913
    • 654 Posts
    Hi,
    I have a template variable which is defined as "Delimited Text" and which contains a list of song titles. I would like to be able to access each of these titles individually and I thought that by defining the TV as "delimited text" that it would get passed to a chunk or snippet as an array that I loop through.

    Is this possible to do and if so could I see a bit of code that would show how to get at the array elements?

    I’ve searched the forum and docs but can’t seem to get this to work. Any pointers would be appreciated and apologies in advance if I have overlooked something.
    Matt
    PS Kludges are accepted smiley
      • 16278
      • 928 Posts
      The delimited text widget will return your data as a string with the list elements separated by the delimiter. You can then use the PHP explode() function to turn it into an array. That would normally apply to a checkbox or multiple select list type of TV.

      What does the rest of your TV definition look like?
      smiley KP
        • 18913
        • 654 Posts
        Upon further review smiley ...

        I think I can forget about the widget and just have the tv defined as text, delimiting the titles with a
        comma for example

        Then it looks like I need to do something like this in the document template :
          [[test_util? &passed_list='name_of_template_variable']]


        Where the snippet "test_util" will deal with it like this
        $passed_list = array_key_exists($passed_list, $modx->documentObject) ? $modx->documentObject[$passed_list][1] : 'album1';

        $titles = explode(',', $passed_list);
        [...]


        At least I think that’ll work ...
        Matt

          • 16278
          • 928 Posts
          I was kind of thinking you might be able to use just a string. wink

          Watch out for the apostrophes in the snippet call - they have to be `back apostrophes`, not ’straight ones’.

          The document object isn’t going to help you retrieve TV values, it only deals in standard document fields like pagetitle etc. But getTemplateVar() should do the trick.
          http://wiki.modxcms.com/index.php/API:documentObject
          http://wiki.modxcms.com/index.php/API:getTemplateVar
          smiley KP