Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Access array element by index #48

Closed
jerowe opened this issue Aug 30, 2017 · 5 comments
Closed

Access array element by index #48

jerowe opened this issue Aug 30, 2017 · 5 comments

Comments

@jerowe
Copy link

jerowe commented Aug 30, 2017

Any chance we could get this implementation?

janl/mustache.js#158 ?

my $array = [1,2,3,4]

my $template = {{ array.1 }}

#Rendering Magic!

Pretty please?

@jerowe
Copy link
Author

jerowe commented Aug 30, 2017

Huh. I can't get dot notation to work in general.

package Decs;

use Moose;
has 'some_hash' => (
    is      => 'rw',
    isa     => 'HashRef',
    default => sub {
        return { 'k1' => 'v1', 'k2' => 'v2' };
    }
);

package Main;

use Template::Mustache;

my $self = Decs->new();

my $template = <<EOT;
{{some_hash.k1}}
EOT

print Template::Mustache->render( $template, $self ), "\n";

Returns

HASH(0x185a810)

What am I missing?

@jerowe
Copy link
Author

jerowe commented Aug 30, 2017

When I'm not using moose it works for hashes, but not arrays. ;-(

my $template = <<EOT;
Value: {{some_hash.k1}}
Element: {{some_list.0}}
EOT

my $thing = {
  some_hash => { 'k1' => 'v1', 'k2' => 'v2' },
  some_list => [1,2,3,4],
};
print Template::Mustache->render( $template, $thing ), "\n";
Value: v1
Element: 

@yanick
Copy link
Owner

yanick commented Aug 30, 2017

The context is not resolved properly when dealing with an object or an array. Expect a patch tonight or tomorrow.

@yanick yanick closed this as completed in 8e80d71 Aug 30, 2017
@jerowe
Copy link
Author

jerowe commented Aug 31, 2017

Awesome! Thanks! I even made it into the tests. ;-)

I'm adding this as an optional templating engine in a project I have going, but I wouldn't have been able to release that functionality without this.

@yanick
Copy link
Owner

yanick commented Aug 31, 2017

On 2017-08-30 11:11 PM, Jillian Rowe wrote:

Awesome! Thanks! I even made it into the tests.

Yup, you're now forever intermeshed into this project. ^.^

Next thing you know, you'll be drawn into making a Pull Request. And then, before you know it, you'll become a co-maintainer. Mark my words...

I'm adding this as an optional templating engine in a project I have going, but I wouldn't have been able to release that functionality without this.

Awesome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants