Kentico form - Display/populate item ID - kentico

I have a Kentico form (bizform) and am able to display all the user's submissions using transformation like below. What I'm unable to display is the item ID value (line 2 in the code below). The field is Kentico-generated field / primary key. What I got is just the text "True" instead of the integer value of the field. It looks so simple, but looks like I missed something very basic. Thanks for help!
<td>{% FirstName %} {% LastName %} </td>
<td>{% demo_requestID %}</td>

You should be able to use something like {% ToInt(demo_requestID) %}

Related

how to get content type in views-view.html.twig files | drupal 8

I have a view in which I show several content types so I need to filter some custom menu entries that I've made in "views-view--myview.html.twig" based on the content type that is shown in the current view.
I've used xdebug but cannot print the content type machine name in my view (I need the content type machine name, not the label!)
Please note that I don't want to do that in the views-view-fields template.
My question is: How can I get the content type (that is shown in a view) in the views-view.html.twig file?
If there is a preprocess function it would also help me!
in views-view.html.twig or overriden twig such as views-view--myview.html.twig you can do the following
get title of first row entity
{{rows[0]['#rows'][0]['#row']._entity.getTitle()}}
get type/bundle of first row entity
{{rows[0]['#rows'][0]['#row']._entity.bundle()}}
So to access all rows you probably need a loop
following checks the entity type/bundle for each row
{% for row in rows[0]['#rows'] %}
{% if row['#row']._entity.bundle() == 'page' %}
<div>its a page</div>
{% endif %}
{% endfor %}
But perhaps the best place to modify individual rows of a view is inside a specific display of a view such as views-view-unformatted.html.twig or views-view-unformatted--myview.html.twig
for comparison get title and type/bundle and looping through rows as above
{{rows[0]['content']['#row']._entity.getTitle()}}
{{rows[0]['content']['#row']._entity.bundle()}}
{% for row in rows %}
{% if row['content']['#row']._entity.bundle() == 'page' %}
<div>its a page</div>
{% endif %}
{% endfor %}

Dynamic variable in Twig, example?

I don't quite understand how the attribute function in Twig works. Can somebody help me with an example?
I have a field in a SQL that is named dynamic. I could be eg "field27", but I don't know the number, the number is saved in radio.id. I would like to do someting like this:
{% for radio in gruppeType.radios %}
<td><!-- value of "field" + radio.id--></td>
{% endfor %}
How can I use field + radio.id as the name of the twig-variable?
You can build the field name with a variable, then use it in the attribute function to access the data within the object/array. As example:
{% set fieldName = "field" ~ radio.id %}
{{ attribute(gruppeType, fieldName) }}
A working example can be seen in this twigfiddle
Hope this helps.

Twig translate dynamic value/string from database

Explanation:
I pull these values from my local database and try to display them on the front-end. The issue is, that I have 2 languages that I need to cater to.
Example:
{% if activeLocale == "si" %}
{{ record.estate_type_SI|raw }}
{% elseif activeLocale == "en" %}
{{ record.estate_type_EN|raw }}
{% endif %}
This works, but when I have multiple items it gets gruesome because I have to write everything down two times. What this does is that depending on the language a value from a different column in the database is pulled.
I am wondering if I can do something similar to this:
{{ record.estate_type_{{"SI"|trans}}|raw }}
I will gladly buy you a beer if you can help me out with this.
Cheers!
EDIT: Variables
Using attribute , you can access a property of an object in a dynamic way. Then you just have to use upper filter to match what you need.
{{ attribute(record, 'estate_type_'~ activeLocale|upper)|raw }}

Retrieve a value inside a field using a custom twig / Select a column by it's block name / Sonata

I'll try to be clear as possible, as my question may not be simple.
I have a Sonata GridPanel, modelled (simplified) like this:
~~~~~~~~~~~~~~~
Name | Type | Blob
~~~~~~~~~~~~~~~
Boby | Aaaa | Bbbb
John | Cccc | Xxxx
Let assume the column Blob is a custom column I made which you can click on.
It is controlled by a custom twig.
My custom twig is like this
{% extends stuff %}
{% block field%}
<div class="opener">
<img
src="{{ asset('bundles/bobby/images/map_magnify.png') }}"
width="30"
height="30"
style="cursor:pointer;"
onclick="createPopUp('{{ admin.id(object) }}');"
>
</div>
{% endblock %}
As you can see, I pass the {{ admin.id(object) }} as a parameters of the function, so the function in my JS file will be aware of the value returned by the parameters.
For example, according to my grid there and assuming the ID of my object is the column Name, if I click on Bbbb, the {{ admin.id(object) }} will return Boby as a value.
This is working.
Now, I want to do quite the same thing, but not returns the ID of a whole object, but a specific value of an object.
Still according to my example, if I click on Bbbb, I would like to retrieve the value contained in the column Type for this object. The value should be then Aaaa.
But I don't know how to do this.
I tried to pass this {{ block('field') }}, but it does not target a specific column. How can I select the block by it's name.
I'm not familiar enough with twig and I'm quite lost looking inside all the Sonata's twig files.
How could I do this ?
You'll have to know to that in my case, the value I want to retrieve is "controlled" by a Sonata's Twig, and not by my custom twig.
I think you can do this using object var from the template:
{% extends stuff %}
{% block field%}
<div class="opener">
<img
src="{{ asset('bundles/bobby/images/map_magnify.png') }}"
width="30"
height="30"
style="cursor:pointer;"
onclick="createPopUp('{{ object.type }}');"
>
</div>
{% endblock %}
Take a look at row templates from sonata admin documentation for more informations

Twig Access Array Index?

Is it possible to directly access an array index from within a Twig template?
Here's my setup, using Silex:
return $app['twig']->render('template', array('numbers' => array('one', 'two', 'three')));
so can I do something like this?
{{numbers[0]}}
Just before posting this I realized, that's exactly what you can do, but as I didn't find the answer anywhere in the docs or google (correct me if I'm wrong), I've posted this anyway.
{{numbers[0]}}
The answer of Adam, is correct, only to make it clear and improve,
you can have access directly to array index
{{ myArray[0] }}
if you need to access in a loop
{% set arrayOfItems = ['ZERO', 'ONE'] %}
{% set myArray = ['APPLE', 'ORANGE'] %}
{% for oneItem in arrayOfItems %}
<p>{{ oneItem }} equals {{ myArray[loop.index0] }}</p>
{% endfor %}
in this example I used an array inside a non related loop so the result is:
ZERO equals APPLE
ONE equals ORANGE
Thats actually something what doesnt work for me when using Twig with shopware 6.
I try to access an object like
{{ page.cart.lineItems.elements[0].quantity }}
what will lead into a parsing error of the Twig Template
I can use
{{ page.cart.lineItems.elements | first }}
to get the first Element, but dont know how i can then access a property of this first element

Resources