Avatar of Bruce Gust
Bruce GustFlag for United States of America

asked on 

Unable to parse "key=date"...

Here's my code:

			 {% for key, val in activity.meta %}
				<div class="box-item">
					{{% if key=="date" }}
					good times
					{{ %endif %}}
					<strong>{{key}}</strong>:<span>{{val}}</span>
				</div>
                {% endfor %} 

Open in new window


The "for" loop works fine (this is a working app that I've been asked to do so changes on). What I need to do is capture the date (see screenshot below) and reformat it. I'm spitting in the wind, though, as far as how the data is actually being processed.


When I run the above code, I get this error:

Error compiling twig template C:\wamp64\www\bSmart\views\partials\company-slide-out\history-tab.html.twig:
TwigException: Unable to parse 'if key=="date"' at template position1
Error parsing twig template C:\wamp64\www\bSmart\views\companies-edit.html.twig:
TypeError: Cannot read property 'length' of undefined

So, I'm thinking "date" is not the name of the key. So, how do I determine the name...?

Is there a way to view the array as it's coming to the twig file so I can see the key->value pairs and know what those keys are specifically?

If this was a JS file, I would do a console.log. Right now, while I have an idea as to where the data is coming from, I'm not certain at this point and that may be another question for EE down the road.

Is there a way to see the raw data in the context of a twig file?

Here's the screenshot I mentioned earlier:

User generated image
What do you think?
Node.jsJavaScript

Avatar of undefined
Last Comment
Bruce Gust
Avatar of Alex [***Alex140181***]
Alex [***Alex140181***]
Flag of Germany image

Can you iterate over
activity.meta

Open in new window

 like:
$.each(activity.meta, function( k, v ) {alert( "Key: " + k + ", Value: " + v );});

Open in new window

?!

from https://api.jquery.com/jquery.each/ 
SOLUTION
Avatar of Alex [***Alex140181***]
Alex [***Alex140181***]
Flag of Germany image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
ASKER CERTIFIED SOLUTION
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of Bruce Gust
Bruce Gust
Flag of United States of America image

ASKER

Guys, I was able to figure it out based on your counsel.

Initially, I was thinking I needed to "see" my keys, but then I realized that this:

<strong>{{key}}</strong>:<span>{{val}}</span>

...was giving me everything I needed, as far as what the actual "leys" were.

So, this is what is going to get my pot on the stove:

{% for key, val in activity.meta %}
            <div class="box-item">
               {% if key=="date" %}
                  <strong>{{key}}</strong>:<span>{{<I'll need to reformat the date here> val}}</span>
               {% endif %}
            </div>
                {% endfor %} 

Open in new window


Thanks!

Now, I've got to figure out how to reformat the date. If you're willing, that question is here: https://www.experts-exchange.com/questions/29177878/How-can-I-format-this-incoming-date-date-in-a-twig-environment.html#questionAdd 

JavaScript
JavaScript

JavaScript is a dynamic, object-based language commonly used for client-side scripting in web browsers. Recently, server side JavaScript frameworks have also emerged. JavaScript runs on nearly every operating system and in almost every mainstream web browser.

127K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo