How to iterate objects in Handlebars? - handlebars.js

I have such a json file. My code below doesn't work. How to iterate "name" in Handlebars?
{ "test": [ { "33": { "name": "Prova 1", "surname": "Federico" } }, { "34": { "name": "Prova 2", "surname": "Antonio " } }, { "35": { "name": "Prova 3", "surname": "Giovanni" } } ] }
<div>
{{debug}}
{{#each test}}
<ul>
<li>{{name}}</li>
</ul>
{{/each}}
</div>

You have to do a double iterating one on test the second on the object in the array to get all properties (I use {{this}} because the name change every time) because name is nested in another object :
{{#each test}}
<ul>
<li>{{#each this}}{{name}}{{/each}}</li>
</ul>
{{/each}}
If you wanted to make work the code you've given you had to have such a json :
{ "test": [
{ "name": "Prova 1", "surname": "Federico" },
{ "name": "Prova 2", "surname": "Antonio " },
{ "name": "Prova 3", "surname": "Giovanni" }
] }
You can check the snippet below that will demonstrate it with your data:
$(document).ready(function() {
var context = {
"test": [{
"33": {
"name": "Prova 1",
"surname": "Federico"
}
},
{
"34": {
"name": "Prova 2",
"surname": "Antonio "
}
},
{
"35": {
"name": "Prova 3",
"surname": "Giovanni"
}
}
]
};
var source = $("#sourceTemplate").html();
var template = Handlebars.compile(source);
var html = template(context);
$("#resultPlaceholder").html(html);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.0.5/handlebars.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script id="sourceTemplate" type="text/x-handlebars-template">
<div>
{{#each test}}
<ul>
<li>{{#each this}}{{name}}{{/each}}</li>
</ul>
{{/each}}
</div>
</script>
<br/>
<div id="resultPlaceholder">
</div>

<ul>{{#test}}<li>{{name}}</li>{{/test}}</ul>
try this

Related

One or more parameter values were invalid: Missing the key Sensor in the item

I am trying to put items within the table and getting this error:
This is the objects.json file I am trying to insert into the db:
{
"Sensors":{
"L": [
{ "M": {
"Sensor": { "S": "Sensor1" },
"SensorDescription": { "S": "This is a description of a Sensor"},
"ImageFile": {"S": "/Sensors/image/Sensor1.txt"},
"SampleRate": {"N": "1"},
"Locations": {"S": "Orlando, FL"}
}
},
{ "M": {
"Sensor": { "S": "Sensor2" },
"SensorDescription": { "S": "This is a description of a Sensor"},
"ImageFile": {"S": "/Sensors/image/Sensor2.txt"},
"SampleRate": {"N": "2"},
"Locations": {"S": "Annapolis, MD"}
}
},
{ "M": {
"Sensor": { "S": "Sensor3" },
"SensorDescription": { "S": "This is a description of a Sensor"},
"ImageFile": {"S": "/Sensors/image/Sensor3.txt"},
"SampleRate": {"N": "3"},
"Locations": {"S": "Jacksonville, FL"}
}
},
{ "M": {
"Sensor": { "S": "Sensor4" },
"SensorDescription": { "S": "This is a description of a Sensor"},
"ImageFile": {"S": "/Sensors/image/Sensor4.txt"},
"SampleRate": {"N": "4"},
"Locations": {"S": "Balitimore, MD"}
}
},
{ "M": {
"Sensor": { "S": "Sensor5" },
"SensorDescription": { "S": "This is a description of a Sensor"},
"ImageFile": {"S": "/Sensors/image/Sensor5.txt"},
"SampleRate": {"N": "5"},
"Locations": {"S": "Washington DC"}
}
},
{ "M": {
"Sensor": { "S": "Sensor6" },
"SensorDescription": { "S": "This is a description of a Sensor"}
}
},
{ "M": {
"Sensor": { "S": "Sensor7" },
"SensorDescription": { "S": "This is a description of a Sensor" }
}
},
{ "M": {
"Sensor": { "S": "Sensor8" },
"SensorDescription": { "S": "This is a description of a Sensor"}
}
},
{ "M": {
"Sensor": { "S": "Sensor9" },
"SensorDescription": { "S": "This is a description of a Sensor"}
}
},
{ "M": {
"Sensor": { "S": "Sensor10" },
"SensorDescription": { "S": "This is a description of a Sensor"}
}
},
{ "M": {
"Sensor": { "S": "Sensor11" },
"SampleRate": {"N": "11"},
"Locations": {"S": "New York, NY"}
}
},
{ "M": {
"Sensor": { "S": "Sensor12" },
"SampleRate": {"N": "12"},
"Locations": {"S": "Buffalo, NY"}
}
},
{ "M": {
"Sensor": { "S": "Sensor13" },
"SampleRate": {"N": "13"},
"Locations": {"S": "Chicago, IL"}
}
},
{ "M": {
"Sensor": { "S": "Sensor14" },
"SampleRate": {"N": "14"},
"Locations": {"S": "Trenton, NJ"}
}
},
{ "M": {
"Sensor": { "S": "Sensor15" },
"SampleRate": {"N": "15"},
"Locations": {"S": "Los Angeles, CA"}
}
},
{ "M": {
"Sensor": { "S": "Sensor16" },
"SampleRate": {"N": "16"},
"SensorDescription": { "S": "This is a description of a Sensor"},
"AltName": {"S": "Sensor-16"}
}
},
{ "M": {
"Sensor": { "S": "Sensor17" },
"SampleRate": {"N": "17"},
"SensorDescription": { "S": "This is a description of a Sensor"},
"Date": {"S": "2022-09-11 15:00:00.000"}
}
},
{ "M": {
"Sensor": { "S": "Sensor18" },
"SampleRate": {"N": "18"},
"SensorDescription": { "S": "This is a description of a Sensor"},
"Working": {"BOOL": false }
}
},
{ "M": {
"Sensor": { "S": "Sensor19" },
"SampleRate": {"N": "19"},
"SensorDescription": { "S": "This is a description of a Sensor"},
"color": {"S": "Green" }
}
},
{ "M": {
"Sensor": { "S": "Sensor20" },
"SampleRate": {"N": "20"},
"SensorDescription": { "S": "This is a description of a Sensor"},
"Senor_type": {"S": "Type 2" }
}
}
]
}
}
Here is the table:
My eyes must be playing tricks on me because I can't see the issue or am I doing something else wrong? Any help is greatly appreciated.
Apparently my description of the issue is too short so I am writing this sentence so I may post..
While the previous answer by hunterhacker is correct, put-item cannot be used to insert batches of items. Instead, to insert a batch of items we must use batch-write-item which will allow us insert up to 25 items per batch:
https://docs.aws.amazon.com/cli/latest/reference/dynamodb/batch-write-item.html
For your use-case, you will need to alter your JSON slightly to make it work. I have edited your example given which you can further refer to and use:
{
"Sensors": [
{
"PutRequest": {
"Item": {
"Sensor": {
"S": "Sensor1"
},
"SensorDescription": {
"S": "This is a description of a Sensor"
},
"ImageFile": {
"S": "/Sensors/image/Sensor1.txt"
},
"SampleRate": {
"N": "1"
},
"Locations": {
"S": "Orlando, FL"
}
}
}
},
{
"PutRequest": {
"Item": {
"Sensor": {
"S": "Sensor2"
},
"SensorDescription": {
"S": "This is a description of a Sensor"
},
"ImageFile": {
"S": "/Sensors/image/Sensor2.txt"
},
"SampleRate": {
"N": "2"
},
"Locations": {
"S": "Annapolis, MD"
}
}
}
},
{
"PutRequest": {
"Item": {
"Sensor": {
"S": "Sensor3"
},
"SensorDescription": {
"S": "This is a description of a Sensor"
},
"ImageFile": {
"S": "/Sensors/image/Sensor3.txt"
},
"SampleRate": {
"N": "3"
},
"Locations": {
"S": "Jacksonville, FL"
}
}
}
},
{
"PutRequest": {
"Item": {
"Sensor": {
"S": "Sensor4"
},
"SensorDescription": {
"S": "This is a description of a Sensor"
},
"ImageFile": {
"S": "/Sensors/image/Sensor4.txt"
},
"SampleRate": {
"N": "4"
},
"Locations": {
"S": "Balitimore, MD"
}
}
}
},
{
"PutRequest": {
"Item": {
"Sensor": {
"S": "Sensor5"
},
"SensorDescription": {
"S": "This is a description of a Sensor"
},
"ImageFile": {
"S": "/Sensors/image/Sensor5.txt"
},
"SampleRate": {
"N": "5"
},
"Locations": {
"S": "Washington DC"
}
}
}
},
{
"PutRequest": {
"Item": {
"Sensor": {
"S": "Sensor6"
},
"SensorDescription": {
"S": "This is a description of a Sensor"
}
}
}
},
{
"PutRequest": {
"Item": {
"Sensor": {
"S": "Sensor7"
},
"SensorDescription": {
"S": "This is a description of a Sensor"
}
}
}
},
{
"PutRequest": {
"Item": {
"Sensor": {
"S": "Sensor8"
},
"SensorDescription": {
"S": "This is a description of a Sensor"
}
}
}
},
{
"PutRequest": {
"Item": {
"Sensor": {
"S": "Sensor9"
},
"SensorDescription": {
"S": "This is a description of a Sensor"
}
}
}
},
{
"PutRequest": {
"Item": {
"Sensor": {
"S": "Sensor10"
},
"SensorDescription": {
"S": "This is a description of a Sensor"
}
}
}
},
{
"PutRequest": {
"Item": {
"Sensor": {
"S": "Sensor11"
},
"SampleRate": {
"N": "11"
},
"Locations": {
"S": "New York, NY"
}
}
}
},
{
"PutRequest": {
"Item": {
"Sensor": {
"S": "Sensor12"
},
"SampleRate": {
"N": "12"
},
"Locations": {
"S": "Buffalo, NY"
}
}
}
},
{
"PutRequest": {
"Item": {
"Sensor": {
"S": "Sensor13"
},
"SampleRate": {
"N": "13"
},
"Locations": {
"S": "Chicago, IL"
}
}
}
},
{
"PutRequest": {
"Item": {
"Sensor": {
"S": "Sensor14"
},
"SampleRate": {
"N": "14"
},
"Locations": {
"S": "Trenton, NJ"
}
}
}
},
{
"PutRequest": {
"Item": {
"Sensor": {
"S": "Sensor15"
},
"SampleRate": {
"N": "15"
},
"Locations": {
"S": "Los Angeles, CA"
}
}
}
},
{
"PutRequest": {
"Item": {
"Sensor": {
"S": "Sensor16"
},
"SampleRate": {
"N": "16"
},
"SensorDescription": {
"S": "This is a description of a Sensor"
},
"AltName": {
"S": "Sensor-16"
}
}
}
},
{
"PutRequest": {
"Item": {
"Sensor": {
"S": "Sensor17"
},
"SampleRate": {
"N": "17"
},
"SensorDescription": {
"S": "This is a description of a Sensor"
},
"Date": {
"S": "2022-09-11 15:00:00.000"
}
}
}
},
{
"PutRequest": {
"Item": {
"Sensor": {
"S": "Sensor18"
},
"SampleRate": {
"N": "18"
},
"SensorDescription": {
"S": "This is a description of a Sensor"
},
"Working": {
"BOOL": false
}
}
}
},
{
"PutRequest": {
"Item": {
"Sensor": {
"S": "Sensor19"
},
"SampleRate": {
"N": "19"
},
"SensorDescription": {
"S": "This is a description of a Sensor"
},
"color": {
"S": "Green"
}
}
}
},
{
"PutRequest": {
"Item": {
"Sensor": {
"S": "Sensor20"
},
"SampleRate": {
"N": "20"
},
"SensorDescription": {
"S": "This is a description of a Sensor"
},
"Senor_type": {
"S": "Type 2"
}
}
}
}
]
}
Now to insert this into your table, you can use the following batch-write-item command:
aws dynamodb batch-write-item \
--request-items file://sensors.json \
--return-consumed-capacity TOTAL
Hope that helps :)
The put-item call takes a singular item and you’re trying to pass a list. You can see the docs and format definition at https://docs.aws.amazon.com/cli/latest/reference/dynamodb/put-item.html

adjusting angularjs material design data table column width

I'm using the old AngularJS Material Design Data Table and would like to know how to adjust the column width.
https://github.com/daniel-nagy/md-data-table
For instance if I wanted to change the 'fat' column in the demo to a fixed width of 40px how would I go about this?
Demo: http://codepen.io/anon/pen/BjvLVJ
There is a fixed padding which seems to be the main problem.
table.md-table.md-row-select td.md-cell:nth-child(n+3):nth-last-child(n+2), table.md-table.md-row-select th.md-column:nth-child(n+3):nth-last-child(n+2) {
 padding: 0 56px 0 0;
}
You could use the following css class.
.width-override{
width:40px !important;
padding:0px !important;
}
You will need to add it to the th and td tags of the respective column like so.
<th md-column md-numeric md-order-by="fat.value" class="width-override"><span>Fat (g)</span></th>
<td md-cell class="width-override">{{dessert.fat.value | number: 2}}</td>
Please checkout the below example!
Note: The contents are of width 56px so the column is of that width, you might want to use the same, since we do not want to clip the contents inside the column.
angular.module('demoApp', ['ngMaterial', 'md.data.table'])
.config(['$mdThemingProvider', function ($mdThemingProvider) {
'use strict';
$mdThemingProvider.theme('default')
.primaryPalette('blue');
}])
.controller('nutritionController', ['$mdEditDialog', '$q', '$scope', '$timeout', function ($mdEditDialog, $q, $scope, $timeout) {
'use strict';
$scope.selected = [];
$scope.limitOptions = [5, 10, 15];
$scope.options = {
rowSelection: true,
multiSelect: true,
autoSelect: true,
decapitate: false,
largeEditDialog: false,
boundaryLinks: false,
limitSelect: true,
pageSelect: true
};
$scope.query = {
order: 'name',
limit: 5,
page: 1
};
$scope.desserts = {
"count": 9,
"data": [
{
"name": "Frozen yogurt",
"type": "Ice cream",
"calories": { "value": 159.0 },
"fat": { "value": 6.0 },
"carbs": { "value": 24.0 },
"protein": { "value": 4.0 },
"sodium": { "value": 87.0 },
"calcium": { "value": 14.0 },
"iron": { "value": 1.0 }
}, {
"name": "Ice cream sandwich",
"type": "Ice cream",
"calories": { "value": 237.0 },
"fat": { "value": 9.0 },
"carbs": { "value": 37.0 },
"protein": { "value": 4.3 },
"sodium": { "value": 129.0 },
"calcium": { "value": 8.0 },
"iron": { "value": 1.0 }
}, {
"name": "Eclair",
"type": "Pastry",
"calories": { "value": 262.0 },
"fat": { "value": 16.0 },
"carbs": { "value": 24.0 },
"protein": { "value": 6.0 },
"sodium": { "value": 337.0 },
"calcium": { "value": 6.0 },
"iron": { "value": 7.0 }
}, {
"name": "Cupcake",
"type": "Pastry",
"calories": { "value": 305.0 },
"fat": { "value": 3.7 },
"carbs": { "value": 67.0 },
"protein": { "value": 4.3 },
"sodium": { "value": 413.0 },
"calcium": { "value": 3.0 },
"iron": { "value": 8.0 }
}, {
"name": "Jelly bean",
"type": "Candy",
"calories": { "value": 375.0 },
"fat": { "value": 0.0 },
"carbs": { "value": 94.0 },
"protein": { "value": 0.0 },
"sodium": { "value": 50.0 },
"calcium": { "value": 0.0 },
"iron": { "value": 0.0 }
}, {
"name": "Lollipop",
"type": "Candy",
"calories": { "value": 392.0 },
"fat": { "value": 0.2 },
"carbs": { "value": 98.0 },
"protein": { "value": 0.0 },
"sodium": { "value": 38.0 },
"calcium": { "value": 0.0 },
"iron": { "value": 2.0 }
}, {
"name": "Honeycomb",
"type": "Other",
"calories": { "value": 408.0 },
"fat": { "value": 3.2 },
"carbs": { "value": 87.0 },
"protein": { "value": 6.5 },
"sodium": { "value": 562.0 },
"calcium": { "value": 0.0 },
"iron": { "value": 45.0 }
}, {
"name": "Donut",
"type": "Pastry",
"calories": { "value": 452.0 },
"fat": { "value": 25.0 },
"carbs": { "value": 51.0 },
"protein": { "value": 4.9 },
"sodium": { "value": 326.0 },
"calcium": { "value": 2.0 },
"iron": { "value": 22.0 }
}, {
"name": "KitKat",
"type": "Candy",
"calories": { "value": 518.0 },
"fat": { "value": 26.0 },
"carbs": { "value": 65.0 },
"protein": { "value": 7.0 },
"sodium": { "value": 54.0 },
"calcium": { "value": 12.0 },
"iron": { "value": 6.0 }
}
]
};
$scope.editComment = function (event, dessert) {
event.stopPropagation(); // in case autoselect is enabled
var editDialog = {
modelValue: dessert.comment,
placeholder: 'Add a comment',
save: function (input) {
if(input.$modelValue === 'Donald Trump') {
input.$invalid = true;
return $q.reject();
}
if(input.$modelValue === 'Bernie Sanders') {
return dessert.comment = 'FEEL THE BERN!'
}
dessert.comment = input.$modelValue;
},
targetEvent: event,
title: 'Add a comment',
validators: {
'md-maxlength': 30
}
};
var promise;
if($scope.options.largeEditDialog) {
promise = $mdEditDialog.large(editDialog);
} else {
promise = $mdEditDialog.small(editDialog);
}
promise.then(function (ctrl) {
var input = ctrl.getInput();
input.$viewChangeListeners.push(function () {
input.$setValidity('test', input.$modelValue !== 'test');
});
});
};
$scope.toggleLimitOptions = function () {
$scope.limitOptions = $scope.limitOptions ? undefined : [5, 10, 15];
};
$scope.getTypes = function () {
return ['Candy', 'Ice cream', 'Other', 'Pastry'];
};
$scope.loadStuff = function () {
$scope.promise = $timeout(function () {
// loading
}, 2000);
}
$scope.logItem = function (item) {
console.log(item.name, 'was selected');
};
$scope.logOrder = function (order) {
console.log('order: ', order);
};
$scope.logPagination = function (page, limit) {
console.log('page: ', page);
console.log('limit: ', limit);
}
}]);
body,
md-content {
background-color: #f5f5f5 !important;
}
body > md-toolbar {
z-index: 3;
}
md-toolbar.md-table-toolbar.alternate {
color: #1e88e5;
background-color: #e3f2fd;
}
md-toolbar.md-table-toolbar.alternate .md-toolbar-tools {
font-size: 16px;
}
md-card:first-child {
padding: 8px 8px 8px 24px;
}
.checkboxes > md-checkbox {
margin: 0;
padding: 16px;
min-width: 300px;
flex: 0 0 auto;
}
.width-override{
width:40px !important;
padding:0px !important;
overflow:hidden;
}
<html lang="en" ng-app="demoApp">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Demo</title>
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/angular_material/1.0.0/angular-material.min.css">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link rel="stylesheet" href="https://rawgit.com/daniel-nagy/md-data-table/master/dist/md-data-table.css">
</head>
<body layout="column">
<md-toolbar class="md-whiteframe-1dp">
<div class="md-toolbar-tools">
<div class="md-title">Material Design Data Table</div>
</div>
</md-toolbar>
<md-content laout="column" flex ng-controller="nutritionController">
<md-card>
<div layout="row" layout-wrap class="checkboxes">
<md-checkbox ng-model="options.rowSelection">Row Selection</md-checkbox>
<md-checkbox ng-model="options.multiSelect">Multiple Selection</md-checkbox>
<md-checkbox ng-model="options.autoSelect">Auto Selection</md-checkbox>
<md-checkbox ng-model="options.decapitate">Decapitate</md-checkbox>
<md-checkbox ng-model="options.largeEditDialog">Lard Edit Dialogs</md-checkbox>
<md-checkbox ng-model="options.boundaryLinks">Pagination Boundary Links</md-checkbox>
<md-checkbox ng-model="options.limitSelect" ng-click="toggleLimitOptions()">Pagination Limit Select</md-checkbox>
<md-checkbox ng-model="options.pageSelect">Pagination Page Select</md-checkbox>
</div>
</md-card>
<md-card>
<md-toolbar class="md-table-toolbar md-default" ng-hide="options.rowSelection && selected.length">
<div class="md-toolbar-tools">
<span>Nutrition</span>
<div flex></div>
<md-button class="md-icon-button" ng-click="loadStuff()">
<md-icon>refresh</md-icon>
</md-button>
</div>
</md-toolbar>
<md-toolbar class="md-table-toolbar alternate" ng-show="options.rowSelection && selected.length">
<div class="md-toolbar-tools">
<span>{{selected.length}} {{selected.length > 1 ? 'items' : 'item'}} selected</span>
</div>
</md-toolbar>
<md-table-container>
<table md-table md-row-select="options.rowSelection" multiple="{{options.multiSelect}}" ng-model="selected" md-progress="promise">
<thead ng-if="!options.decapitate" md-head md-order="query.order" md-on-reorder="logOrder">
<tr md-row>
<th md-column md-order-by="name"><span>Dessert (100g serving)</span></th>
<th md-column md-order-by="type"><span>Type</span></th>
<th md-column md-numeric md-order-by="calories.value" md-desc><span>Calories</span></th>
<th md-column md-numeric md-order-by="fat.value" class="width-override"><span>Fat (g)</span></th>
<th md-column md-numeric md-order-by="carbs.value"><span>Carbs (g)</span></th>
<th md-column md-numeric md-order-by="protein.value"><span>Protein (g)</span></th>
<th md-column md-numeric md-order-by="sodium.value" hide-gt-xs show-gt-md><span>Sodium (mg)</span></th>
<th md-column md-numeric md-order-by="calcium.value" hide-gt-xs show-gt-lg><span>Calcium (%)</span></th>
<th md-column md-numeric md-order-by="iron.value" hide-gt-xs show-gt-lg><span>Iron (%)</span></th>
<th md-column md-order-by="comment">
<md-icon>comments</md-icon>
<span>Comments</span>
</th>
</tr>
</thead>
<tbody md-body>
<tr md-row md-select="dessert" md-on-select="logItem" md-auto-select="options.autoSelect" ng-disabled="dessert.calories.value > 400" ng-repeat="dessert in desserts.data | filter: filter.search | orderBy: query.order | limitTo: query.limit : (query.page -1) * query.limit">
<td md-cell>{{dessert.name}}</td>
<td md-cell>
<md-select ng-model="dessert.type" placeholder="Other">
<md-option ng-value="type" ng-repeat="type in getTypes()">{{type}}</md-option>
</md-select>
</td>
<td md-cell>{{dessert.calories.value}}</td>
<td md-cell class="width-override">{{dessert.fat.value | number: 2}}</td>
<td md-cell>{{dessert.carbs.value}}</td>
<td md-cell>{{dessert.protein.value | number: 2}}</td>
<td md-cell hide-gt-xs show-gt-md>{{dessert.sodium.value}}</td>
<td md-cell hide-gt-xs show-gt-lg>{{dessert.calcium.value}}%</td>
<td md-cell hide-gt-xs show-gt-lg>{{dessert.iron.value}}%</td>
<td md-cell ng-click="editComment($event, dessert)" ng-class="{'md-placeholder': !dessert.comment}">
{{dessert.comment || 'Add a comment'}}
</td>
</tr>
</tbody>
</table>
</md-table-container>
<md-table-pagination md-limit="query.limit" md-limit-options="limitOptions" md-page="query.page" md-total="{{desserts.count}}" md-page-select="options.pageSelect" md-boundary-links="options.boundaryLinks" md-on-paginate="logPagination"></md-table-pagination>
</md-card>
</md-content>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-animate.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-aria.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angular_material/1.0.0/angular-material.min.js"></script>
<script src="https://rawgit.com/daniel-nagy/md-data-table/master/dist/md-data-table.js"></script>
</body>
</html>

How Do i shrink to fit image the banner IN SHOPIFY

How Do i shrink to fit image the banner IN SHOPIFY
i am new to shopify not sure how it works so let me know if you have any suggestion. i have attached few example so you have an idea what i am talking about.
<div class="slider-area" data-section-id="{{ section.id }}" data-section-type="slideshow-section">
<div class="slider-active owl-carousel">
{% for block in section.blocks %}
<div class="single-slider single-slider-book1 bg-img" style="background-image: url({% if block.settings.slider_bg_image %}
{{ block.settings.slider_bg_image | img_url: 'master' }}
{% else %}https://via.placeholder.com/1545x950{% endif %})">
<div class="container">
<div class="slider-animation slider-content-book fadeinup-animated {% if block.settings.slider_content_position_right %}content_right{% endif %}">
{% if block.settings.slider_title_1 != '' %}
<h1 class="animated" style="color: {{ block.settings.slider_title_1_color }}">{{ block.settings.slider_title_1 }}</h1>
{% endif %}
{% if block.settings.slider_title_2 != '' %}
<h2 class="animated" style="color: {{ block.settings.slider_title_2_color }}">{{ block.settings.slider_title_2 }}</h2>
{% endif %}
{% if block.settings.slider_subtitle != '' %}
<p class="animated" style="color: {{ block.settings.slider_subtitle_color }}">{{ block.settings.slider_subtitle }}</p>
{% endif %}
{% if block.settings.slider_btn_text != '' %}
<a href="{{ block.settings.slider_btn_url }}" style="color: {{ block.settings.slider_btn_color }};
background-color: rgba({{ block.settings.slider_btn_bg_color }}, 1)">
{{ block.settings.slider_btn_text }}</a>
{% endif %}
</div>
</div>
</div>
{% endfor %}
</div>
</div>
{% for block in section.blocks %}
<style>
.slider-content-book h1 span {color: {{ block.settings.slider_title_1_span_color }};}
.slider-animation.slider-content-book.content_right {text-align: right;}
.slider-animation.slider-content-book.content_right p {margin-left: auto;}
.slider-content-book > a:hover {box-shadow: 0 10px 35px -7px rgba({{ block.settings.slider_btn_bg_color }}, 0.9);}
</style>
{% endfor %}
<script>
$('.slider-active').owlCarousel({
loop: true,
nav: false,
autoplay: {% if section.settings.slider_autoplay_enable %}true{% else %}false{% endif %},
autoplayTimeout: 5000,
animateOut: 'fadeOut',
animateIn: 'fadeIn',
item: 1,
rtl:true,
responsive: {
0: {
items: 1
},
768: {
items: 1
},
1000: {
items: 1
}
}
})
</script>
{% schema %}
{
"name": "Slider- Book",
"settings": [
{
"type": "checkbox",
"id": "slider_autoplay_enable",
"label": "Enable Slider Autoplay",
"default": true
}
],
"blocks": [
{
"type": "slide",
"name": "Slide",
"settings": [
{
"type": "image_picker",
"id": "slider_bg_image",
"label": "Slider BG Image"
},
{
"type": "header",
"content": "Slider Content"
},
{
"type": "checkbox",
"id": "slider_content_position_right",
"label": "Slider Content Position Right",
"default": false
},
{
"type": "text",
"id": "slider_title_1",
"label": "Title 1",
"default": "<span>Knowledge</span> is",
"info": "Use '<span>' tag for color text e.g. <span>Knowledge</span> is"
},
{
"type": "text",
"id": "slider_title_2",
"label": "Title 2",
"default": "Power."
},
{
"type": "textarea",
"id": "slider_subtitle",
"label": "Sub-title",
"default": "Lorem Ipsum is simply dummy text of the printing and typesetting industry."
},
{
"type": "text",
"id": "slider_btn_text",
"label": "Button Text",
"default": "More Books"
},
{
"type": "url",
"id": "slider_btn_url",
"label": "Button URL",
"default": "\/collections\/all"
},
{
"type": "header",
"content": "Color [See More Color](https:\/\/www.w3schools.com/colors/colors_picker.asp)"
},
{
"type": "color",
"id": "slider_title_1_color",
"label": "Title 1 Color"
},
{
"type": "color",
"id": "slider_title_1_span_color",
"label": "Title 1 span text Color"
},
{
"type": "color",
"id": "slider_title_2_color",
"label": "Title 2 Color"
},
{
"type": "color",
"id": "slider_subtitle_color",
"label": "Sub-title Color"
},
{
"type": "color",
"id": "slider_btn_color",
"label": "Button text Color"
},
{
"type": "text",
"id": "slider_btn_bg_color",
"label": "Button BG Color",
"info": "Put RGB value e.g. 56, 40 , 25"
}
]
}
],
"presets":[
{
"name": "Slider- Book",
"category": "slider",
"blocks":[
{
"type": "slide"
},
{
"type": "slide"
}
]
}
]
}
{% endschema %}
3 different screen with same picture
TABLET SCREEN
DESKTOP SCREEN
PHONE SCREEN
ACTUAL IMAGE
you can see a preview here
https://stashcbd-com.myshopify.com/?preview_theme_id=31932481611
The image size ( if you are referring to the original size of the image ) is controlled via the filter img_url: 'master' at the moment. But that syntax is deprecated. You can read more here: https://help.shopify.com/themes/liquid/filters/deprecated-filters#named-size-parameters
So the proper way to size the image is to use specific sizes instead:
{{ block.settings.slider_bg_image | img_url: '2048x2048' }}
Where 2048x2048 is width and height.
Now if you are referring to sizing down the image via CSS, that's a whole different story and you don't have problems with the Shopify logic but with the CSS and the question is not asked properly.

React-Table column fixed width spoils whole table

Can someone explain this to me why i cant set fixed width on First Name column?It's setting passed width but it spoils whole table.If you tinker with resizing(by mouse) the column other columns will appear.Is this due to flebox?Im not familiar with flexbox.
var ReactTable = ReactTable.default
class App extends React.Component {
constructor() {
super();
this.state = {
data: []
};
}
render() {
const { data } = this.state;
return (
<div>
<ReactTable
data={data}
columns={[
{
Header: "Name",
columns: [
{
width:'50',
Header: "First Name",
accessor: "firstName"
},
{
Header: "Last Name",
id: "lastName",
accessor: d => d.lastName
}
]
},
{
Header: "Info",
columns: [
{
Header: "Age",
accessor: "age"
},
{
Header: "Status",
accessor: "status"
}
]
},
{
Header: 'Stats',
columns: [
{
Header: "Visits",
accessor: "visits"
}
]
}
]}
defaultPageSize={10}
className="-striped -highlight"
/>
<br />
</div>
);
}
}
ReactDOM.render(<App />, document.getElementById("app"));
<link href="https://cdnjs.cloudflare.com/ajax/libs/react-table/6.5.3/react-table.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-table/6.5.3/react-table.js"></script>
<div id="app"></div>
If anyone can add react-table to the tags i will be glad.
I don't know much about react-table, but try to not use quotes
var ReactTable = ReactTable.default
class App extends React.Component {
constructor() {
super();
this.state = {
data: []
};
}
render() {
const { data } = this.state;
return (
<div>
<ReactTable
data={data}
columns={[
{
Header: "Name",
columns: [
{
Header: "First Name",
accessor: "firstName",
width: 50
},
{
Header: "Last Name",
id: "lastName",
accessor: d => d.lastName
}
]
},
{
Header: "Info",
columns: [
{
Header: "Age",
accessor: "age"
},
{
Header: "Status",
accessor: "status"
}
]
},
{
Header: 'Stats',
columns: [
{
Header: "Visits",
accessor: "visits"
}
]
}
]}
defaultPageSize={10}
className="-striped -highlight"
/>
<br />
</div>
);
}
}
ReactDOM.render(<App />, document.getElementById("app"));
<link href="https://cdnjs.cloudflare.com/ajax/libs/react-table/6.5.3/react-table.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-table/6.5.3/react-table.js"></script>
<div id="app"></div>
I don't know much about react-table, but you can solve this by setting width to all the columns.
var ReactTable = ReactTable.default
class App extends React.Component {
constructor() {
super();
this.state = {
data: []
};
}
render() {
const { data } = this.state;
return (
<div>
<ReactTable
data={data}
columns={[
{
Header: "Name",
columns: [
{
width:'50',
Header: "First Name",
accessor: "firstName"
},
{
width:'100',
Header: "Last Name",
id: "lastName",
accessor: d => d.lastName
}
]
},
{
Header: "Info",
columns: [
{
width:'100',
Header: "Age",
accessor: "age"
},
{
width:'100',
Header: "Status",
accessor: "status"
}
]
},
{
Header: 'Stats',
columns: [
{
width:'100',
Header: "Visits",
accessor: "visits"
}
]
}
]}
defaultPageSize={10}
className="-striped -highlight"
/>
<br />
</div>
);
}
}
ReactDOM.render(<App />, document.getElementById("app"));
<link href="https://cdnjs.cloudflare.com/ajax/libs/react-table/6.5.3/react-table.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-table/6.5.3/react-table.js"></script>
<div id="app"></div>

Using one json file in multiple partials

I'm working on a page that needs navigation at the top of the page and in the footer. The nav itself is the same bar a few class/layout changes so I would like to keep it in one json file. Is that possible?
At the moment, only the footer gets populated. I am using grunt-assemble to build the html templates.
JSON:
{
"pages": [
{
"linkTitle": "page 1",
"subnav": [
{
"subNavLinkTitle": "temp",
"url": "temp.html"
},
{
"subNavLinkTitle": "form",
"url": "form.html"
},
{
"subNavLinkTitle": "map",
"url": "map.html"
}
]
},
{
"linkTitle": "page 2",
"subnav": [
{
"subNavLinkTitle": "sub page 4",
"url": "#"
},
{
"subNavLinkTitle": "sub page 5",
"url": "#"
},
{
"subNavLinkTitle": "sub page 6",
"url": "#"
},
{
"subNavLinkTitle": "sub page 7",
"url": "#"
},
{
"subNavLinkTitle": "sub page 8",
"url": "#"
}
]
}
]
}
layout:
<!DOCTYPE html>
<html lang="en">
<head>
{{> header }}
</head>
<body>
{{> top }}
{{> body }}
{{> footer }}
</body>
</html>
top:
<ol class="nav-top">
{{#each nav.pages}}
<li>
{{ linkTitle }}<i></i>
<div class="sub-nav">
<ul>
{{#each subnav}}
<li>{{ subNavLinkTitle }}</li>
{{/each}}
</ul>
</div>
</li>
{{/each}}
</ol>
footer:
<ol class="nav-footer">
{{#each nav.pages}}
<li>
<span class="section">{{ linkTitle }}</span>
<ul>
{{#each subnav}}
<li>{{ subNavLinkTitle }}</li>
{{/each}}
</ul>
</li>
{{/each}}
</ol>
I think what you have should work, but just in case, try referencing the file along with your partials:
{{> top nav }}
Then inside your top partial, just use:
{{#each pages }}
That's how I've done similar things in the past without issue...

Resources