DirtyBirdNJ
DirtyBirdNJ

Reputation: 602

Adding views/blocks programatically to tpl.php files in Drupal 7

I am trying to integrate the awkward showcase into my page--front.tpl.php. My first idea was to create a custom content type (slideshow image) and then a view that prints a list of those images. I was able to create the view and set it to be available as a block... but I have no idea how to include that block via my .tpl.php file. I don't want to just use the content region because it displays a bunch of "hello welcome to $sitename" messages that I couldn't figure out how to remove.

Also, what is the naming convention for views blocks? The machine name for the view I want to create a template of is called 'front_page_slideshow'

Upvotes: 0

Views: 2555

Answers (2)

rafinskipg
rafinskipg

Reputation: 519

There's a way of adding views programatically,

the easiest way is using "views_embed_view()" http://api.drupal.org/api/views/views.module/function/views_embed_view/7

$view = views_embed_view('view_name', 'display', $args);
print $view;

For render a block (any kind of block) use this simple script I created:

https://gist.github.com/4001153

Upvotes: 2

readyman
readyman

Reputation: 11

I would create a region['slideshow'] in your template. Then you assign the view that you've already created into it as a block. If you want to get really simple, till you figure how to drupal properly, you can just hack your page--front.tpl.php file and use include('yourslideshowfile.php'); to simply include your file there.

Upvotes: 1

Related Questions