Is it possible to programatically insert an existing view into a block generated by a custom module and pass it a parameter?

I am generating a block based on some external api data. I have been asked to add a view that pulls in related content from the website. To do this I would like pass a view to my block and pass it a parameter I extract from the api data.

Can this be done, and if so... how?


Just like in D7, using views_embed_view.

print views_embed_view('view_name','machine_name', $parameter);

In case you are wondering, this is the machine_name


$parameter = 1;
print views_embed_view('hello_world','block_1', $parameter);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.