I access the twig instance, and render the template like so:
return $this->template->render('login.html', array(
'name' => 'John Smith',
'age' => 32,
'location' => 'Egypt'
));
Here is the template side of things
Hello, my name is {{ name }}, my age is {{ age }}, and my location is {{ location }}.
Currently prints out
Hello, my name is , my age is , and my location is .
Should print out
Hello, my name is John Smith, my age is 32, and my location is Egypt.
Related
I would like to use this type of request with sequelize to make large number of updates in one request (for performance reasons) :
UPDATE employee
SET address = new.address,
name = new.name
from (values :updateStack) AS new(address, name, employeeId)
WHERE employee.id = new.employeeId
Here is the value of updateStack :
[{
address: 'France',
name: 'Chris',
employeeId: 21
}, {
address: 'UK',
name: 'Steve',
employeeId: 42
}]
I'm not sure how sequelize can properly parse the updateStack array.
Any idea ?
This SQL query is working fine :
UPDATE employee
SET address = new.address,
name = new.name
from (values ('France', 'Chris', 21), ('UK', 'Steve', 42)) AS new(address, name, employeeId)
WHERE employee.id = new.employeeId
Thank you and have a good day.
I've discovered how to do it !
sequelize.query(
`
UPDATE employee
SET address = new.address,
name = new.name
from (values ?) AS new(address, name, employeeId)
WHERE employee.id = new.employeeId
`,
{
replacements: [['France', 'Chris', 21], ['UK', 'Steve', 42]],
type: models.models.sequelize.QueryTypes.INSERT
}
)
I am using Nodejs and Mongodb with Mongoose. My model contains following properties:
first_name
last_name
status
I need to use mongoose find functions to search users with these 3 fields. I have 2 parameters:
full_name: Craig de Zia
status: alive
For example, I have a name called Craig de Zia. I don't know which parts of the name are first name or last name, so I want to search FULL name. And I want to connect full name and status with "$and" logic. The condition structure would be like:
'$and': [
{ 'full_name': 'Craig de Zia' },
{ status: 'alive' },
]
The problem is that there is no full_name field in the database. We need to combine first_name field and last_name field. How can I do this?
Manage first_name and last_name as per condition
db.collection.find({
$and: [
{
$expr: { $eq: ['Craig de Zia', { $concat: ["$first_name", "$last_name"] }] }
},
{ 'status': 'alive' }
]
})
Please manage first_name and last_name here $concat as "first_namelast_name" and if you want to search
first_name and last_name with space in between them then use
{ $concat: ["$first_name", " ", "$last_name"] }
I need the title to show the (current date - 1)
When I hard code a value eg "17"
This is where the component is displaying (in index)
{% include 'home/key-facts' with {
content: {
keyFactsHeading: entry.keyFactsHeading,
keyFacts: entry.keyFacts,
keyFactsSmall: entry.keyFactsSmall,
}
Which is this file here --->
This is how I've included the date
{% include '_components/bg-type' with {
content: {
title: {{ "now"|date('Y') - 1 }}
},
} only %}
I am passing content.title into here --->
<div class="bg-type">
<div class="bg-type__text bg-type--large">
{{ content.title }}
</div>
</div>
When hardcoding the value as below it works fine but when I add
title: {{ "now"|date('Y') - 1}} I get a 500 error.
{% include '_components/bg-type' with {
content: {
title: 17
},
} only %}
Why is this? Can you also explain why what I'm trying doesn't work?
I've tried dumping {{ "now"|date('Y') - 1}} and I can see the year I want
The {{ ... }} notation is used to output data. In this case you only want to pass data towards an include. Notice you already inside a twig-statement, {% include .... %}
The correct syntax would be
{% include '_components/bg-type' with {
content: {
title: "now"|date('Y') - 1,
},
} only %}
i have user object that contain all user fields.
and listFields array that have ["user.id", "user.email","user.gender"].
so variables in string.
i want to loop listFields and print it's original value from user object
currently user.id user.email print on screen.
i want to print it's value in screen.
have any solution for this! or it is possible?
Mycode
{% for fieldName in listFields %}
<td>
{{ fieldName }}
</td>
{% endfor %}
If you want to print dynamic variables u can make use of the function attribute:
{% set user_fields = [ 'user.id', 'user.email', 'user.gender', 'alice.email', 'bob.id', 'bob.foo', ] %}
{% for field in user_fields %}
{{ attribute(attribute(_context, (field|split('.'))[0])|default([]), (field|split('.'))[1])|default(null) }}
{% endfor %}
demo
array:3 [▼
"user" => array:3 [▼
"id" => 42
"email" => "user#example.com"
"gender" => 0
]
"bob" => array:3 [▼
"id" => 1
"email" => "bob#example.com"
"gender" => 0
]
"alice" => array:3 [▼
"id" => 100
"email" => "alice#example.com"
"gender" => 1
]
]
I am using post request With JSON Object:
{
"name": "Emmy",
"age": 11,
"state": "Goa",
"country": "india"
}
my CSV file is :
name,age,state,country
Emmy,11,Goa,india
and my artilery code :
config:
target: 'http://localhost:5000'
phases:
- duration: 60
arrivalRate: 10
defaults:
headers:
token: 'TOKEN'
payload:
path: "./hello.csv"
fields:
- "name"
- "age"
- "state"
- "country"
scenarios:
- flow:
- post:
url: "url"
json:
name: "{{name}}"
age: "{{age}}"
state: "{{state}}"
country: "{{country}}"
I have validation for each field in which age will take only integer values but artillery is taking string values so i an getting validation error. how to pass age as integer in yaml file.
If you don't find any other solution, you can run custom code :
function setJSONBody(requestParams, context, ee, next) {
return next(); // MUST be called for the scenario to continue
}
doc : https://artillery.io/docs/http-reference/#advanced-writing-custom-logic-in-javascript
To explicitly load a string enclosed in quotes as an integer in YAML, you need to add the !!int tag:
---
integer: !!int "{{ variable }}"
It is needed in this case, because a plain scalar cannot start with { as this is starting a flow style mapping.
However, this won't work if the substitution of the {{ var }} happens after loading and resolving the tag, because then it would try to resolve the verbatim string {{ var }} as an integer which will fail.
Here's an article about Tags/Schemas/Types in YAML 1.1 and 1.2 I wrote in December which might help understanding:
Introduction to YAML Schemas and Tags