How can I embed a view in a template when passing view name and parameters are passed as variables? 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-&gt;loadMultiple() (line 266 of core/lib/Drupal/Core/Entity/EntityStorageBase.php). Warning: Illegal offset type in isset or empty in Drupal\Core\Entity\EntityStorageBase-&gt;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-&gt;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.
Try to avoid using {{ content }} this way. The position you have found in the render array in your last comment can change anytime when reconfiguring the paragraph type or when installing/updating code. Render arrays are not APIs and they are only required to have valid renderable child elements at the lowest level, but not a fixed structure.

The Entity API on the other hand, which you would use to access {{ paragraph }} in a paragraph template, does not change, at least not without a transition period while you can still use a deprecated API.

Example:

// field value like string or number
{{ paragraph.field_example.value }}

// target id of a reference field
{{ paragraph.field_reference.target_id }}


See also https://drupal.stackexchange.com/a/263285/47547.