I am working with a trading partner who sends me JSON with embedded spaces in the keys. For example
[{"BANK ID":89769876976,"Account Number":789698769876,"Account Type":"CHECKING","Balance":1187.65...
and I cannot find a way to access the keys using angular {{ }} expressions. Any clues?
You can just use the bracket notation (without the dot)
<div ng-repeat="acct in accounts">
Bank Id: {{ acct['BANK ID'] }},
Account Number: {{ acct['Account Number'] }},
Type: {{ acct['Account Type'] }},
Balance: {{ acct.Balance }}
</div>
Here is a Demo
Related
I learning django rest. And now i wont output some json data in html. My json:
{'Resul': {'Period Start': '2017-01-01', 'Period End': '2017-12-12'}}
then i send it json to html:
context = {'Resul': json_data['date']}
content = render_to_string('balance.html', context)
json_data['date'] - {'Period Start': '2017-01-01', 'Period End': '2017-12-12'}
in html i write this code
Period: {{ Resul['Period Start'] }} - {{ Resul['Period End'] }}
but have error:
Could not parse the remainder: '['Period Start']' from 'Resul['Period Start']'
I strongly recommend you not to use spaces in dictionary key names, change them for underscores and do it like this:
Period: {{ Resul.Period_Start }} - {{ Resul.Period_End }}
I have a CSV file in my _data folder and I am trying to specify the row of the CSV to access in my Front Matter and then return specific columns from the CSV based on the row specificed in the Front Matter.
Here's the CSV file:
name,description
Dallas,Big City in Texas
And here's the contents of my index.html file:
---
city: "Dallas"
---
{{ site.data.data[page.city].description }}
Per the Jekyll Docs page on using data files, I should be able to use this syntax to access data files in this way, but the compiled html file does not include any data.
I have tested other ways of accessing the contents of the CSV file and those work, so it doesn't appear to be a problem with the data file or the site itself but rather with using the [ ] array id Liquid syntax.
Looks like you have misunderstood the [] notation for a hash structure.
I will first orient you on how the [] is supposed to work..
Expanding your data.csv a bit:
name,description
Dallas,Big City in Texas
Houston,Another City in Texas
and "inspecting" your the data object obtained from the above CSV file,
{{ site.data.data | inspect }}
on building the site, you'll see that the resultant object is simply an Array of Hashes :
<p>
[
{"name"=>"Dallas", "description"=>"Big City in Texas"},
{"name"=>"Houston", "description"=>"Another City in Texas"}
]
</p>
which means you can only access individual hash entry by referencing its index number.
i.e. {{ site.data.data[0] }} will give you the first hash and {{ site.data.data[1] }} will give you the next hash.
and therefore {{ site.data.data[0].description }} will give you the result you expect to get:
<p>
Big City in Texas
</p>
Now that you know how [] works for data hashes, lets simply get to the solution.
To access elements in an Array, one can simply iterate through the Array objects and reference necessary entries:
{% for entry in site.data.data %}
<div>
<span>{{ entry.name }}</span> : <span>{{ entry.description }}</span>
</div>
{% endfor %}
will give you:
<div>
<span>Dallas</span>
<span>Big City in Texas</span>
</div>
<div>
<span>Houston</span>
<span>Another City in Texas</span>
</div>
I have following case:
Route::get('/kids_report_card/{id?}/{param?}', 'KidsReportCardController#index');
And in view file I have:
{{ url('kids_report_card/4') }}
In some other view file I have:
{{ url('kids_report_card/name') }} (where name is string here-some parameter)
Now the situation is:
For {{ url('kids_report_card/4') }} ,Route::get('/kids_report_card/{id?}/{param?}', 'KidsReportCardController#index'); works fine.
For {{ url('kids_report_card/name') }},Route::get('/kids_report_card/{id?}/{param?}', 'KidsReportCardController#index'); doesn't work fine as in url we have name parameter while in Route we have first parameter as id(integer value). so is there any dynamic solution that srting parameter must go to second parameter in Route??
You can pass an array of parameters in the url like this:
{{ url('kids_report_card', ['name' => 'name_value']) }}
Reference: URL's
I get the JSON from the site. Some of the fields of this JSON is empty (""). I have a HTML(Jade) code like this:
div(ng-repeat="item in itemsToDisplay", class="item tableLine")
span(class="tableItemid")
a(href="#/itemDetail/{{ item.Itemid }}") {{ item.Itemid }}
span(class="tableItemdescription")
{{ item.Itemdescription }}
span(class="tableDate")
{{ item.CreationDate }}
span(class="tableCountry")
{{ item.Address }}
And css (slylus) like this:
span.tableItemid
col(1/15)
span.tableItemdescription
col(3/15)
span.tableDate
col(2/15)
If the fields is empty the span is empty. And I have offset in the responsive grid. What is the best way to avoid it?
I would like to know how to shorten text content retrieved to get a preview instead of getting a block of text in the html template
From: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
To:
aaaaaaaaaaaaaaaaaaaaaaaaaaa....
The code that is used to retrieve the contents is :
<a class="list_content" href="/qna/view" onclick="document.forms['q_title_{{ q.id }}'].submit(); return false" title="{{ q.content }}">{{ q.content }} </a><br/>
Many thanks!
If you are using Django 1.4, truncatechars filter will be the best way to go:
{{ q.content|truncatechars:25 }}
Assuming that "q.content" is a string you could use the slice command:
{{ q.content|slice:":255" }}
truncatechars template filter for django 1.4