Hi, I want to have an edit this link on my node pages. Is there a better way to do it then something like this?:
global $user; if($user->uid) { echo 'edit'; }
I can't believe there's no built-in check to see if the logged in user is allowed to edit the node or not.
You can use hook_link() to do this:
function module_name_link($type, $node = NULL, $teaser = FALSE) { $links = array(); if ($type == 'node') { if (node_access('update', $node)) { $links['node_edit'] = array( 'title' => t('Edit'), 'href' => "node/$node->nid/edit", 'attributes' => array('title' => t('Edit this node.')) ); } } return $links; }
Placed in a module, this will add a link to the $links variable (where the "read more" link goes).
The key bit is node_access('update', $node). That's the built-in check you're looking for.
node_access('update', $node)
massive, thanks I'm gonna try that
There was enough info here to get what I needed done. Thanks.
In my node template, I just used:
<?php if (node_access('update', $node)) { print l("Edit", "node/$node->nid/edit"); } ?>
For me it worked to just put {$tabs} above the {$content} in my template... silly me.
Could you add a code sample to illustrate?
It's just print $tabs; - themes should already do this by default, in most cases. They're the tabs that display up the top of nodes.
print $tabs;
Ah ye sorry, I use smarty so.. :)
Isn't it just {$tabs} or {tabs} or something, then?
yea
{$tabs} {$title} {$help} {$messages} {$content}
stuff like that
Comments
You can use hook_link() to
You can use hook_link() to do this:
Placed in a module, this will add a link to the $links variable (where the "read more" link goes).
The key bit is
node_access('update', $node). That's the built-in check you're looking for.massive, thanks I'm gonna
massive, thanks I'm gonna try that
There was enough info here
There was enough info here to get what I needed done.
Thanks.
In my node template, I just used:
For me it worked to just put
For me it worked to just put {$tabs} above the {$content} in my template... silly me.
Could you add a code sample
Could you add a code sample to illustrate?
It's just <?php print $tabs;
It's just
print $tabs;- themes should already do this by default, in most cases. They're the tabs that display up the top of nodes.Ah ye sorry, I use smarty
Ah ye sorry, I use smarty so.. :)
Isn't it just {$tabs} or
Isn't it just {$tabs} or {tabs} or something, then?
yea
yea
{$tabs}
{$title}
{$help}
{$messages}
{$content}
stuff like that