posted this on drupal.org forums as well. Any help or pointing in the right direction would be much appreciated

henns20's picture

hello:

i am studying php .... but don't even know where to look for the source of this issue...

Problem

i have used the php snippet to print a views block on my node-frontpage.tpl.php:

<?php
$block
= module_invoke('views', 'block', 'view', 'popular_alltime');
print
$block['content'];
?>

  • B article ()
  • A article ()
  • D article ()
  • C article ()
  • E article ()

why is it printing out '()'
any help on this or pointing in the right direction would be much appreciated.

Comments

what should it print?

jkopel's picture

A little more context would help.

What is the view supposed to return, what does the content look like, do you have any views themeing functions in your template, and what color are your socks?

I am also curious as to why you are invoking this programmatically in the node-frontpage.tpl.php, as opposed to simply adding the block through the blocks admin?

As a final note, I have often found the answers to my views related issues by also giving the view in question a page, and then examining the output of the view there.

josh

Partner - Number 10 Web company (www.number10webcompany.com)

socks are white with white polka dots....

henns20's picture

sorry about that...i get frustrated when people post an issue and make it diffucult for a person trying to help to picture the scenario...

The view is supposed to generate just the title field of the most popular nodes on the site.... It is doing that in this case but at the end of the titel it is also generating the function symbol ()....

I am invoking this programmtically because in the blocks adminster you are limited with the placement of the block to regions (footer, sidebars, etc...) ...for instance....I only want this view on my homepage and i would like it in the content portion of the node...

my noded-frontpage.tpl.php is a cck generated custom content node with in addition to 2 views block underneath the cck fields - (image field, links fields, and clearing both underneath will be the 2 invoked views blocks)

sure i will also try and give it a page view and see if i can figure anything out on that...

just a note on this: i have been successful creating a custom view and invoking it into a node (the view in question now is a default view in drupal install)...it seems that when i use the default view and try to use this snippet ....it either does not show or i have this problem.... my thinking right now is just to create another custom view for a work around...but i was trying to see if there is a better solution first so i can also get a greater understanding what is happening.

thanks for the response

henns20

interesting

jkopel's picture

I guess in retrospect I have never tried this with one of the default views, but..
My method of invoking a view directly in a template is as follows:

<?php
//get the view
$view = views_get_view('view_name_here');

//build the view
//$args is an array of arguments to pass in
//$use_pager - boolean, default FALSE
//$limit - int, default 0
//$page - int, default 0
$block = views_build_view('block', $view, $args, $use_pager, $limit, $page);
print
$block ;
?>

I think in the end this is essentially the same as your way, except it starts at a lower level, and does not use the module_invoke to call hook_block.

I like it mainly because I can control the arguments I am passing in. I am guessing that that is where your issue is, and you should check out what the view arguments title fields are doing (I bet they are wrapping something like (%1))

Hope this helps!

Josh

Partner - Number 10 Web company (www.number10webcompany.com)

thanks i will check it out and let you know

henns20's picture

yes it that does help---thanks again for the response - that it interesting to see how you went about arriving at it...cheers....jamie

Philadelphia Area

Group organizers

Group categories

Group events

Add to calendar

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds:

Hot content this week