Skip to content

Syntax::TTerse support for looping arrays #124

abraxxa opened this Issue Jul 16, 2014 · 4 comments

2 participants

abraxxa commented Jul 16, 2014

I didn't find a way to loop an array, not arrayref, when using TTerse syntax with Catalyst::View::Xslate.
I'm calling the 'all' method on a DBIx::Class resultset on the Catalyst stash which returns an array of DBIx::Class::Row objects which I want to loop over.

The Xslate project member

Untested. Does this work?

[% FOREACH row IN [ resultset.all() ] %]...[% END %]
abraxxa commented Jul 17, 2014

Unfortunately that doesn't work either:

Text::Xslate: Cannot access 'id' (19 is not a container) (/home/ahartmai/perl5/git/NAC-Web-CIS/root/ at /home/ahartmai/perl5/perlbrew/perls/20/lib/site_perl/5.20.0/Catalyst/ line 65.
    [% FOREACH devicegroup IN [ groups.all() ] %]
    <li[% IF navlist == %] id="active"[% END %]><a href="[% c.uri_for_action(c.controller('Device').action_for('list'), [ ]) %]">[% devicegroup.devicegroupname %]</a></li>
    [% END %] 
The Xslate project member

Yeah, I read the docs again, and xslate only allows scalar context on return values. I think you're just going to have to inject a all_arrayref() or something on your Resultset (DBIC allows you to do this, IIRC)

abraxxa commented Jul 21, 2014

I've tried using Kolon and Metakolon and they also don't allow iterating over arrays returned from a has_many relationship or the all method. I'm giving up on Xslate as long as this feature isn't added as it's too much work for too less benefit. I was hoping to find a template language that is less hassle than TT but Xslate isn't any better at the moment for me.

@abraxxa abraxxa closed this Jul 21, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.