Variable as a collectionKey?

  • Hi,


    I'm using this to output multiple collections, (I've removed the rest of the template to keep things clear)

    Code
    1. perch_collection(['Listen Up', 'Case Studies', 'Publications', 'Resources'], [
    2. // TEMPLATE ETC...
    3. },


    It works, but I was wondering if I could set the collectionKeys as a variable like this:


    $test = "'Listen Up', 'Case Studies', 'Publications', 'Resources'";


    As expected, this echoes as:


    'Listen Up', 'Case Studies', 'Publications', 'Resources'


    The same as the collectionKeys, so how come this doesn't work? $test is set at the top of my template, before the perch_collection.

    Code
    1. perch_collection([$test], [
    2. // TEMPLATE ETC...
    3. },


    perch:debug shows this error:


    No matching collections found. Check collection name ('Listen Up', 'Case Studies', 'Publications', 'Resources').



    Even though they are the correct collection names? :/

  • Hi Stephen,


    This is an array of strings:


    PHP
    1. $array = ['Listen Up', 'Case Studies', 'Publications', 'Resources'];


    This is a single string:


    PHP
    1. $string = "'Listen Up', 'Case Studies', 'Publications', 'Resources'";


    You need to use an array:


    PHP
    1. $collectionKeys = ['Listen Up', 'Case Studies', 'Publications', 'Resources'];
    2. perch_collection($collectionKeys, [
    3.     'count' => 10,
    4. ]);
  • Thanks for the reply,


    PHP
    1. $result = [$wlrs_selected];
    2. print_r ($result);


    So, $result is an array, print_r gives me


    PHP
    1. Array
    2. (
    3. [0] => 'Listen Up', 'Publications', 'Case Studies'
    4. )


    Unfortunately, I still get the same error when I try to use $result as a collectionKey?


    PHP
    1. perch_collection( $result, [
    2. 'count' => 10,
    3. ]);


    Error:


    No matching collections found. Check collection name ( 'Listen Up', 'Publications', 'Case Studies').



    UPDATE:


    I must be doing something funky to get $result = [$wlrs_selected]; - I'll have to go back to the drawing board on this one!


    If I manually create an array, like this


    PHP
    1. $test_array = ['Listen Up', 'Case Studies', 'Publications'];
    2. print_r ($test_array);

    I get this:


    Array ( [0] => Listen Up [1] => Case Studies [2] => Publications )


    and $test_array works:


    PHP
    1. perch_collection( $test_array, [
    2. 'count' => 10,
    3. ]);
  • The is an array with a single element (a string):



    This is an array of strings:


    Hope this helps.