Twig_Error_Syntax The function "use" does not exist yii2 - twig

{{'<h1>Profile</h1>'}}
{{
use('yii\helpers\Html')
}}
{{ GridView.widget({
'dataProvider': dataProvider,
'columns':[
'username',
'password',
'email',
'mon_no',
],
})|raw}}
the error is
Twig_Error_Syntax :
The function "use" does not exist

Related

e_validation_failure: validation exception adonisjs

I am facing this error "e_validation_failure: validation exception" only on prod enviroment... I am using Adonis 5, in my local everything runs correctly, in stage as well.
my controller looks like this:
public async store({ request, response }: HttpContextContract) {
response.header('Cache-Control', 'no-cache, no-store');
try {
const payload = await request.validate(SignupUserValidator);
await UserService.store(payload);
return responseWithSuccess(response);
} catch (error) {
return responseWithError(response, error.message);
}
}
my validator looks like this:
import { schema, rules } from '#ioc:Adonis/Core/Validator';
import { HttpContextContract } from '#ioc:Adonis/Core/HttpContext';
import { UserRoleEnum } from 'Contracts/enums';
export default class SignupUserValidator {
constructor(protected ctx: HttpContextContract) {}
public schema = schema.create({
first_name: schema.string({ trim: true }, [rules.minLength(2)]),
last_name: schema.string({ trim: true }, [rules.minLength(2)]),
password: schema.string({}, [rules.minLength(8), rules.confirmed()]),
email: schema.string({}, [
rules.email(),
rules.unique({ table: 'users', column: 'email' }),
]),
role: schema.enum([UserRoleEnum.CLIENT, UserRoleEnum.COWORKING] as const),
photo_id: schema.number.optional([rules.exists({ table: 'photos', column: 'id' })]),
personal_address: schema.object.optional().members({
fulltext: schema.string.optional({ trim: true }),
latitude: schema.number.optional(),
longitude: schema.number.optional(),
city: schema.string.optional(),
state: schema.string.optional(),
country: schema.string.optional({ trim: true }),
}),
personal_phone: schema.string({}, [rules.maxLength(14), rules.minLength(10)]),
cowork: schema.object
.optional([rules.requiredWhen('role', '=', UserRoleEnum.COWORKING)])
.members({
name: schema.string({ trim: true }),
email: schema.string.optional({}, [
rules.email(),
rules.unique({ table: 'cowork_accounts', column: 'email' }),
]),
phone: schema.string.optional({}, [rules.maxLength(14), rules.minLength(10)]),
photo_id: schema.number.optional([
rules.exists({ table: 'photos', column: 'id' }),
]),
}),
client: schema.object
.optional([rules.requiredWhen('role', '=', UserRoleEnum.CLIENT)])
.members({
company_name: schema.string.optional({ trim: true }),
company_email: schema.string.optional({}, [rules.email()]),
company_phone: schema.string.optional({}, [
rules.maxLength(14),
rules.minLength(10),
]),
company_address: schema.object.optional().members({
fulltext: schema.string.optional({ trim: true }),
latitude: schema.number.optional(),
longitude: schema.number.optional(),
country: schema.string.optional({ trim: true }),
}),
company_photo_id: schema.number.optional([
rules.exists({ table: 'photos', column: 'id' }),
]),
}),
});
public messages = {
minLength: 'The {{ field }} must be at least {{ options.minLength }} characters',
maxLength: 'The {{ field }} must have at most {{ options.maxLength }} characters',
required: 'The {{ field }} is required',
exists: 'The {{ field }} is invalid',
number: 'The {{ field }} must be a number',
string: 'The {{ string }} must be a string',
'password_confirmation.confirmed': 'The passwords are different',
'email.email': 'The email is not valid',
'email.unique': 'User with email address already exists',
'cowork.requiredWhen': 'The cowork object must be sent when the user is a coworking',
'cowork.email.email': 'The email is not valid',
'cowork.email.unique': 'Company with email address already exists',
'client.requiredWhen': 'The client object must be sent when the user is a client',
};
My request looks like this:
{
"first_name": "Dan",
"last_name": "Abreu",
"password": "secret1233",
"password_confirmation": "secret1233",
"email": "test#gmail.com",
"role": "CLIENT",
"personal_phone": "1234567890",
"photo_id": null,
"personal_address": {
"fulltext": "Rua do Lead",
"city":"Gravatá",
"state":"Pe",
"country":"Brazil",
"longitude": -10.00,
"latitude": 1.00
},
"client": {
"company_name": "my company",
"company_email": "test1#gmail.com",
"company_phone": "10800-0000",
"company_photo_id": null,
"company_address": {
"fulltext": "Rua do labrador",
"longitude": -10.00,
"latitude": 1.00
}
}
I am following the rules when creating the validator:
node ace make:validator SignupUserValidator
is anyone facing the same issue on aws ec2 enviroment?
I tried to validate the request with the validator I created and everything works fine on my local and stage env but on prod it does not work.

How to submit matrix and category fields in frontend

So i have an entry to submit games.
The games entry has a lot of different fields, and one of the fields is:
a field with fieldType "category" linked to a category
a field with fieldType "matrix" called materialList that looks like this:
The "MaterialName" has fieldType categories and is linked to a category
So now I am trying to submit a form in my frontend.
So far I managed to correctly save regular text fields, but I failed to correctly save something as a matrix, and I failed to properly save a category that is correctly linked.
I already found an example on https://craftcms.com/knowledge-base/entry-form but this only shows me the regular text fields.
This is the code I have so far:
<form method="post" accept-charset="UTF-8">
{{ csrfInput() }}
{{ actionInput('entries/save-entry') }}
{{ redirectInput('spelen/{slug}') }}
{{ hiddenInput('sectionId', '1') }}
{{ hiddenInput('enabled', '1') }}
<label for="title">Title</label>
{{ input('text', 'title', entry.title, {
id: 'title',
}) }}
{{ _self.errorList(entry.getErrors('title')) }}
<label for="youngestAge">Minimum leeftijd</label>
{{ tag('input', {
id: 'youngestAge',
type: 'number',
name: 'fields[youngestAge]',
text: entry.youngestAge,
}) }}
{{ _self.errorList(entry.getErrors('youngestAge')) }}
<label for="oldestAge">Maximum leeftijd</label>
{{ tag('input', {
id: 'oldestAge',
type: 'number',
name: 'fields[oldestAge]',
text: entry.oldestAge,
}) }}
{{ _self.errorList(entry.getErrors('oldestAge')) }}
<label for="leastAmountOfPlayers">Minimum aantal spelers</label>
{{ tag('input', {
id: 'leastAmountOfPlayers',
type: 'number',
name: 'fields[leastAmountOfPlayers]',
text: entry.leastAmountOfPlayers,
}) }}
{{ _self.errorList(entry.getErrors('leastAmountOfPlayers')) }}
<label for="mostAmountOfPlayers">Maximum aantal spelers</label>
{{ tag('input', {
id: 'mostAmountOfPlayers',
type: 'number',
name: 'fields[mostAmountOfPlayers]',
text: entry.mostAmountOfPlayers,
}) }}
{{ _self.errorList(entry.getErrors('mostAmountOfPlayers')) }}
<label for="groups">Aantal groepen</label>
{{ tag('input', {
id: 'groups',
type: 'number',
name: 'fields[groups]',
text: entry.groups,
}) }}
{{ _self.errorList(entry.getErrors('groups')) }}
<label for="gametime">Speelduur</label>
{{ tag('input', {
id: 'gametime',
type: 'time',
name: 'fields[gametime]',
text: entry.gametime,
}) }}
{{ _self.errorList(entry.getErrors('gametime')) }}
<label for="intro">Intro</label>
{{ tag('input', {
id: 'intro',
type: 'text',
name: 'fields[intro]',
text: entry.intro,
}) }}
{{ _self.errorList(entry.getErrors('intro')) }}
<label for="purpose">Doel van het spel</label>
{{ tag('input', {
id: 'purpose',
type: 'text',
name: 'fields[purpose]',
text: entry.purpose,
}) }}
{{ _self.errorList(entry.getErrors('purpose')) }}
<label for="explenation">Speluitleg</label>
{{ tag('input', {
id: 'explenation',
type: 'text',
name: 'fields[explenation]',
text: entry.explenation,
}) }}
{{ _self.errorList(entry.getErrors('explenation')) }}
<label for="gameType">Spel type</label>
{{ tag('input', {
id: 'gameType',
type: 'text',
name: 'fields[gameType]',
value: 6,
}) }}
{{ _self.errorList(entry.getErrors('gameType')) }}
<label for="materialItem">Material</label>
{{ tag('input', {
id: 'gameType',
type: 'text',
name: 'fields[materialItem]',
value: entry.materialItem,
}) }}
{{ _self.errorList(entry.getErrors('materialItem')) }}
<label for="isPublic">Publiek</label>
{{ tag('input', {
id: 'isPublic',
type: 'checkbox',
name: 'fields[isPublic]',
text: false,
}) }}
{{ _self.errorList(entry.getErrors('isPublic')) }}
<label for="body">Body</label>
{{ tag('textarea', {
id: 'body',
name: 'fields[body]',
text: 'test bericht',
}) }}
{{ _self.errorList(entry.getErrors('body')) }}
<button type="submit">Publish</button>
</form>
So these are the 2 I need help with:
The first input needs to properly save linked categories
The second one needs to properly save a matrix
<label for="gameType">Spel type</label>
{{ tag('input', {
id: 'gameType',
type: 'text',
name: 'fields[gameType]',
value: 6,
}) }}
{{ _self.errorList(entry.getErrors('gameType')) }}
<label for="materialItem">Material</label>
{{ tag('input', {
id: 'gameType',
type: 'text',
name: 'fields[materialItem]',
value: entry.materialItem,
}) }}
{{ _self.errorList(entry.getErrors('materialItem')) }}
So I found out how to save a category, but I'm still stuck on the matrix part.
This is the code for the category:
{# Include a hidden input first so Craft knows to update the existing value
if no checkboxes are checked. #}
{{ hiddenInput('fields[myFieldHandle]', '') }}
{# Get all of the possible category options #}
{% set possibleCategories = craft.categories()
.group('food')
.all() %}
{# Get the currently related category IDs #}
{% set relatedCategoryIds = entry is defined
? entry.myFieldHandle.ids()
: [] %}
<ul>
{% nav possibleCategory in possibleCategories %}
<li>
<label>
{{ input(
'checkbox',
'fields[myFieldHandle][]',
possibleCategory.id,
{ checked: possibleCategory.id in relatedCategoryIds }
) }}
{{ possibleCategory.title }}
</label>
{% ifchildren %}
<ul>
{% children %}
</ul>
{% endifchildren %}
</li>
{% endnav %}
</ul>

Apostrophecms: parseAggregate: expected colon after dict key

I am new in apostrophecms i am building my first app, i want to define widgets in home using macro but When the JS calls nunjucks render, I get the following error::
parseAggregate: expected colon after dict key
this is my Home page:
{#apostrophe-pages/views/home.html#}
{% extends "layout.html" %}
{% import "macros/utils.html" as areas %}
{% block title %}Home{% endblock %}
{% block main %}
<main>
{{ areas.columns() }}
</main>
{% endblock %}
{#views/macros/utils.html#}
{% macro columns() %}
{{ apos.area(data.page, 'main', {
blockLevelControls; true,
widgets: {
'one-column': {},
'two-column': {}
}
}
}) }}
{% endmacro %}
{% macro column(parent, name, imageSize) %}
{{ apos.area(parent, name, {
widgets: {
'apostrophe-rich-text': {
toolbar: [ 'Styles', 'Bold', 'Italic', 'Link', 'Unlink' ],
styles: [
{ name: 'Heading', element: 'h3' },
{ name: 'Subheading', element: 'h4' },
{ name: 'Paragraph', element: 'p' }
]
},
'apostrophe-images': {
size: 'imageSize'
},
'apostrophe-video': {},
'test': {}
}
}) }}
{% endmacro %}
You have a typo in your literal object declaration. Instead of
{{ apos.area(data.page, 'main', {
blockLevelControls; true,
widgets: {
'one-column': {},
'two-column': {}
}
}
}) }}
it should be
{{ apos.area(data.page, 'main', {
blockLevelControls: true, // <- Here is a colon now
widgets: {
'one-column': {},
'two-column': {}
}
}
}) }}

How to pass Data from Test1 Component to Test2 Component in Vue.js?

I have a component called Test1.vue and in it i have a value total:120, i want this value to pass to Test2.vue? how i could to that?
Test1.vue:
<Test2 v-bind:totalPrice='totalValue'></Test2>
data() {
return {
totalValue: 120,
};
},
Test2.vue:
<h3>{{ totali }}</h3> --> Not working
props: {
totalPrice: {
type: Number,
}
},
likes {{ totalPrice }}
in Test2.vue , right?
Try sending your value through props
<Test2 :totalPrice="totalValue"></Test2>
and then use the props in the Test2 Component
export default {
props: {
totalPrice: {
type: Number,
}
}
}
and in the template
<template>
<h2>{{ totalPrice }}</h2>
</template>

Twig tag cannot get resolved inside nav_widget tag

Code is as below:
{{ nav_widget({
'options': {
'class': 'navbar-nav navbar-right',
},
'items': [
{ 'label': "Welcome, {{ app.user.identity.username }}", 'items': [ { 'label': 'Logout', 'url': '/site/logout', 'linkOptions': { 'data-method': 'post' } } ] }
]
}) }}
If the logged in username is 'James', but what displayed on web is still {{ app.user.identity.username }}. Thus the twig tag {{ app.user.identity.username }} is not resolved in such case.
Any suggestions?
Note: this is also raised as an issue in Github.
If you set concatenate strings you should set with ~. "Welcome, " ~ app.user.identity.username
{{ nav_widget({
'options': {
'class': 'navbar-nav navbar-right',
},
'items': [
{ 'label': "Welcome, " ~ app.user.identity.username, 'items': [ { 'label': 'Logout', 'url': '/site/logout', 'linkOptions': { 'data-method': 'post' } } ] }
]
}) }}
See doc

Resources