Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Syntax::TTerse support for looping arrays #124

Closed
abraxxa opened this Issue · 4 comments

2 participants

@abraxxa

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.

@lestrrat
Owner

Untested. Does this work?

[% FOREACH row IN [ resultset.all() ] %]...[% END %]
@abraxxa

Unfortunately that doesn't work either:

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

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

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
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.