Hi,

I'm trying to use in my template page--front.tpl.php the function views_embed_view() from Views 3 to include the last 5 articles to my front page. It is unfortunately not working, even if the preview of the view is giving an output in html.

Here is the code I wrote in the page--front.tpl.php :

<?php
// Attempt 1
$viewsHtml = views_embed_view("last-5-articles");
print $viewsHtml;

// Attempt 2
$block = module_invoke('views', 'block', 'view', "last-5-articles");
print $block['content'];
?>

but I never get some html printed...

What should I add ? I'm a bit confused... :-s Does anyone already seen an include of View 3 in a template working ?
Do you need export of view ?

Thank for helping. Stéphane

Comments

dawehner’s picture

Status: Active » Fixed

Are you 100% sure that the machine readable name of the view is "last-5-articles"? No "-" are allowed by default :)

Click on the export link in the ui. You will see $view->name = "nameoftheview". Use this view instead.

svergeylen’s picture

YES !

Thanks for taking time to read my problem. It was indeed the fact that Drupal replaces the "-" by "_".
The name of the view was thus "last_5_articles" but I didn't know ! Exporting the view was a good thing to do te verify it !

Thanks !

Automatically closed -- issue fixed for 2 weeks with no activity.