Multiple levels of <perch:template> includes doesn't work with one-dimensional arrays passed to perch_template()

  • Hi,


    The online documentation for perch_template() suggests that it should work when using one-dimensional arrays as the data.


    However I have found that when doing this, <perch:template> includes inside other <perch:template> includes do not work.


    See the example below.


    Code: a.html
    1. a<perch:template path="content/b.html"/>


    Code: b.html
    1. b<perch:template path="content/c.html"/>


    Code: c.html
    1. c



    Although it's simple enough to use multi-dimensional arrays all the time, it was not at all obvious how to fix the problem, and as I say, the documentation uses a one-dimensional array in the example.

  • drewm

    Approved the thread.
  • Well if perch_template() is supposed to work with a one-dimensional array, then I'm reporting a bug. Though it is not a problem for me as I have discovered the workaround, I thought I'd report so that others don't spend time with the same issue.


    However, if perch_template() is not supposed to work with a one-dimensional array, then it's an issue with the docs for perch_template().


    I don't mind, but it seems to me like a bug as one-dimensional arrays work almost fine, apart from this one issue.


    Or maybe you're not misremembering and multiple levels of includes shouldn't work, in which case this seems like a pretty big omission in the docs for template includes. I have only ever used multiple levels of template includes when using the perch_template() function, and as I say it works with multi-dimensional arrays but not with one-dimensional arrays. As for what happens when not using perch_template(), I am not sure, though my guess is it would work, based on the fact perch_content_custom always returns a multi-dimensional array even if there is one item.

  • I can confirm that the number of levels of template includes <prech:template> inside a template is not consistent across all contexts.


    I remember testing this for regular (single-item?) content regions and the number of levels for template includes you can use for an edit form template is not the same for display templates for the same region when output with perch_content_custom(). I haven't tested this with a multiple-item region though.


    With Collections I've been able to use more levels for the edit form templates in comparison to a (single-item) region.


    So there may be some inconsistencies across Perch Content functions. Having said that, I don't believe there's anything wrong with the documentation of the function perch_template(). It can be used to render the data of a one-dimensional array as documented. It just happens to allow a limited number of template include levels.