I want to fetch a view in my template_preprocess_node function and then put in in a block, so I can diplay it in the sidebars of my page. I have the view (the code below) but don't know how to put it in a block. Thank you for your help in advance!

    $view = views_get_view('playlist');
    $variables['content']['playlist'] = $view->render();

If you want to draw a view of content based on a node, then you should build a module that declared hook_block(), and that hook_block gets the current node with menu_get_object(), and form the desired view.

At the theming layer, when your node is preprocessed for theming, it's not a good place to construct any blocks. Hope this helps.

  • I got your point and Ive actually made it that way. Thank you for your help! – Ivan Ivanov Feb 27 '14 at 23:41

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.