Formatting row node output for a View
I have a view, let's say: view1
It displays a blog-like summary for a particular content type on my site (say page). I have set the Row Style to node. However, I want to to add one more link to the links section, that's like:
this_user's pages
So, I created a custom file named views-view-row-node--view1.tpl.php. The contents are as follows:
<div id="node-<?php print $node->nid; ?>" class="node<?php if ($sticky) { print ' sticky'; } ?><?php if (!$status) { print ' node-unpublished'; } ?>">
<?php if ($page == 0): ?>
<h2><a href="<?php print $node_url ?>" title="<?php print $title ?>"><?php print $title ?></a></h2>
<?php endif; ?>
<?php if ($submitted): ?>
<span class="submitted"><?php print $submitted; ?></span>
<?php endif; ?>
<div class="content clear-block">
<?php print $content ?>
</div>
<div class="clear-block">
<div class="meta">
<?php if ($taxonomy): ?>
<div class="terms"><?php print $terms ?></div>
<?php endif;?>
</div>
<?php if ($links): ?>
<div class="links">Hello <?php print $links; ?></div>
<?php endif; ?>
</div>
</div>
<?php if ($comments): ?>
<?php print $comments; ?>
<?php endif; ?>Please note that I have added the following to the links section:
Hello
I expected this to appear before links for each node teaser. However, it does not appear anywhere. I clicked on "Rescan templates" on theme information, and it put the file : views-view-row-node--view1.tpl.php in bold.
Any anybody help me how to modify the output of each row (which actually is a node teaser) when row style is set to node.

The problem is You are using
The problem is
You are using node.tpl.php code(variables) inside views template. and the variables you are printing inside views.tpl does not contain any value. when yours views template is being executed it receives some variable see below.
// $Id: views-view.tpl.php,v 1.13 2009/06/02 19:30:44 merlinofchaos Exp $
/**
* @file views-view.tpl.php
* Main view template
*
* Variables available:
* - $css_name: A css-safe version of the view name.
* - $header: The view header
* - $footer: The view footer
* - $rows: The results of the view query, if any
* - $empty: The empty text to display if the view is empty
* - $pager: The pager next/prev links to display, if any
* - $exposed: Exposed widget form/info to display
* - $feed_icon: Feed icon to display, if any
* - $more: A link to view more, if any
* - $admin_links: A rendered list of administrative links
* - $admin_links_raw: A list of administrative links suitable for theme('links')
There is no $links variable available inside views tpl
<?phpif ($links):
?>
Hello
<?phpprint $links;
?>
<?phpendif;
?>
Now trying using views variables inside views template file to theme it you way.
But one thing I'll suggets There is alot you can do using views without overriding views templates . Just use some tricks inside admin/views to get required results.
Thanks
www.drupaldepth.blogspot.com
Access denied by Anonymous users
Ok logged in as root in phpMyAdmin, when to my data base where I could see the access, access log, etc in the left menu. Ran your command above hit go and got this..
Your SQL-query has been executed successfully
SQL-query : [Edit] [Create PHP Code]
TRUNCATE node_access;# MySQL returned an empty result set (i.e. zero rows).
INSERT INTO node_access( nid, gid, realm, grant_view, grant_update, grant_delete )
VALUES ( 0, 0, 'all', 1, 0, 0 ) ;# Affected rows:1
But I'm still getting thing at the home page. or any link I try untill I log in as someone???
Access denied
You are not authorized to access this page.
google
ASHU
Hi drupalhooked, thanx for
Hi drupalhooked, thanx for the reply. It cleared some things up. But it seems now I would have problems trying to achieve what I want to.
Basically, I have a custom node-type (say page), and I want users to see a:
this_user's pages
link in the teaser view, along with other links, (like Add new comment, report to Mollom).
My initial solution was to add fields myself with row style set to fields. However, I also want the links that come up with a default teaser view.
I added "Add new comment" link manually as a field, together with "this_user's pages" link. However, as different modules can add their entries to links, its becoming impracticable * inflexible to add all the fields manually.
What I want is the default teaser view with just one custom link:
this_user's pages
added to the links. As this is a custom node type, there is no module support except for views. Is it possible to accomplish this using views.
--
I always think tomorrow will have more time than today.
And every today seems to pass-by faster than yesterday.
http://www.rahulsingla.com
Ok
ok still a few things clear..
but I think you are a bit confused between node.tpl and views.tpl calling process.
1. when ever you create a view its generated content is never rendered through node.tpl.php.
2. what ever fields you choose to display from a view those will be rendered through any of tpl files inside views module unless you override them.
3. you wrote this "I added "Add new comment" link manually as a field, together with "this_user's pages" link. However, as different modules can add their entries to links, its becoming impracticable * inflexible to add all the fields manually."
If you are creating your own view so no other module can add any link/content to your view.
4. other module can change content of full node view/teaser view only by their module code and so can you usinging drupal's hook_nodeapi
5. if you dont want to use views(which i think not required if am understanding ur issue correctly). simply create
node-.tpl.php and add new links on this file before or after
<?phpif ($links):
?>
<?phpprint $links
?>
<?phpendif
?>
but this approach will make it effective on the currebt theme only which is not a drupal way.
The best method will be doing it using hook_link.
Thanks
Hi drupalhooked, you
Hi drupalhooked, you said:
"1. when ever you create a view its generated content is never rendered through node.tpl.php."
IMHO (and I have tested it), if the Row Style of the view is set to "Node", then the generated content is surely rendered through node.tpl.php.
Again you said:
"If you are creating your own view so no other module can add any link/content to your view."
Again, if the Row Style is set to Node, then modules contributions to the links are definitely present in the view output.
However, as I have posted it in the comment below, you suggestion for using node-page.tpl.php worked when Row Style was set to Node. And I was able to customize the links also.
--
I always think tomorrow will have more time than today.
And every today seems to pass-by faster than yesterday.
http://www.rahulsingla.com
links
Your code will only display 'hello' if you have links. Other modules can add items to the $links, but in a standard install it'll only display taxonomy terms associated with that blog post. Have you got terms associated with your blog posts?
If you are using blog module.
If you are using blog module. then create a node-blog.tpl.php and theme it the way you want. why to use views . just check if($page==1) {// code for full blog node view }
and
if(!$page) {// code for blog node teaser view}
Hi drupalhooked, this helped.
Hi drupalhooked, this helped. I create a node-page.tp.php and put the following in it:
<div id="node-<?php print $node->nid; ?>" class="node<?php if ($sticky) { print ' sticky'; } ?><?php if (!$status) { print ' node-unpublished'; } ?>">
<?php print $picture ?>
<?php if ($page == 0): ?>
<h2><a href="<?php print $node_url ?>" title="<?php print $title ?>"><?php print $title ?></a></h2>
<?php endif; ?>
<?php if ($submitted): ?>
<span class="submitted"><?php print $submitted; ?></span>
<?php endif; ?>
<div class="content clear-block">
<?php print $content ?>
</div>
<div class="clear-block">
<div class="meta">
<?php if ($taxonomy): ?>
<div class="terms"><?php print $terms ?></div>
<?php endif;?>
</div>
<?php if ($links): ?>
<?php
$startIndex = strpos($name, '>');
$endIndex = strpos($name, '<', $startIndex);
$authUsername = substr($name, $startIndex + 1, $endIndex - $startIndex - 1);
?>
<div class="links"><a href="http://www.duringcollege.com/pages/<?php print $authUsername ?>"><?php print $authUsername ?>'s pages</a> <?php print $links; ?></div>
<?php endif; ?>
</div>
</div>
Notice towards its end, I am hacking up to get the username of the user who created the node. Is there any direct way of getting the plain username (not formatted) of the node author??
--
I always think tomorrow will have more time than today.
And every today seems to pass-by faster than yesterday.
http://www.rahulsingla.com
Yes there is a way
Do this inside your node-page.tpl.php
print_r($node);
This will print entire node object containing all the information about current node.
and just a tip one more thing never use hardcoded url like http://www.duringcollege.com/page... instead use url() or l () function :)
so here is your final code just try it, not tested
<?php if ($links): ?><div class="links"><a href="<?php print url('pages/'.$node->name)?>"><?php print $node->name ?>'s pages</a><?php print $links; ?></div>
<?php endif; ?>
Than drupalhooked for that
Than drupalhooked for that code snippet, that worked perfectly.
--
I always think tomorrow will have more time than today.
And every today seems to pass-by faster than yesterday.
http://www.rahulsingla.com