Inside my paragraph template I have variables which contain category id and view machine name. So when I print them like this:
{{ content.field_category }}
{{ content.field_view }}
I get correct values.
Then I'm using twig tweak to embed view and if I embed it with hard-coded values, like this:
{{ drupal_view('view_machine_name', 'embed_1', 33) }}
it also works. I hard-coded the same values my variables display from above.
Now I want to use my field values instead of hard-coded values:
{{ drupal_view(content.field_view, 'embed_1', content.field_category) }}
I get error like:
Warning: array_flip(): Can only flip STRING and INTEGER values! in Drupal\Core\Entity\EntityStorageBase->loadMultiple() (line 266 of core/lib/Drupal/Core/Entity/EntityStorageBase.php). Warning: Illegal offset type in isset or empty in Drupal\Core\Entity\EntityStorageBase->load() (line 251 of core/lib/Drupal/Core/Entity/EntityStorageBase.php).
when I try to replace view parameter and:
InvalidArgumentException: Placeholders must have a trailing [] if they are to be expanded with an array of values. in Drupal\Core\Database\Connection->expandArguments() (line 738 of core/lib/Drupal/Core/Database/Connection.php).
When I try to replace category parameter.
I guess that content.field_category
is not an int value and content.field_view
is not an string, as this twig filter expects but I have no idea how to convert them to those primitive types?
Tried intval
- it's not working
Tried number_format
- also not working
I guess I would have to somehow get view machine name and category id directly from those objects but I don't know how to achieve that.
Tried content.field_category.id()
and content.field_view.id()
Nothing works.
{{ kint() }}
in your template for having all available variables pretty-printed on screen and inspect them. It probably needs to be{{ content.field_view.value }}
or{{ content.field_view.0 }}
(same for the cat field) for printing your field values.{{ drupal_view(content.field_view, 'embed_1', content.field_category.0) }}