This site has been archived and you can no longer log in or post new messages. For up-to-date community resources please visit

eZ Community » Forums » Extensions » ezcomments and $can_edit

ezcomments and $can_edit

ezcomments and $can_edit

Wednesday 15 December 2010 11:53:21 pm - 8 replies


I would like to know if it is possible to determine $can_edit in the template extension/ezcomments/design/standard/templates/comment/view/comment_item.tpl instead of in the template extension/ezcomments/design/standard/templates/comment/edit.tpl ?

I don't understand why the variable $can_edit is available at the top of the template edit.tpl (without any fetch) and not in comment_item.tpl

If this is possible so we can display the links «Edit» and «Delete» (to the bottom of each comment) only if the current user has these rights.

Currently, these 2 links are displayed at the bottom of each comment and we have to click on it to see if we can or not edit / delete the comment.

Modified on Thursday 16 December 2010 12:14:16 am by Pascal France

Thursday 16 December 2010 10:01:32 am


When we are not allowed to edit a comment, an error message is displayed by the template

  • extension/ezcomments/design/standard/templates/comment/edit.tpl

once we have clicked the link «Edit» at the bottom of a comment.

This template does not display a "Back" button with the error message (as is the case with the template extension/ezcomments/design/standard/templates/comment/delete.tpl) and the user must return back to the previous page with the «Back» button of his browser.

I added a button with this code:

<form action={'/comment/edit'|ezurl} method="post" name="CommentEdit">
        <input type="hidden" name="CommentID" value="{$comment_id}" />
        <input type="hidden" name="RedirectURI" value={$redirect_uri|ezurl( , 'full' )} />
               <div class="message-error">
                     {'You don\'t have access to edit.'|i18n( 'ezcomments/comment/edit' )}
                <input type="submit" value="{'Back'|i18n( 'ezcomments/comment/action' )}" class="button" name="CancelButton" />

But the URL «{$redirect_uri|ezurl( , 'full' )}» refers to the root of the site and not to the previous page (which is the case with the template delete.tpl).

The problem I meet is that in the template edit.tpl no one of these variables is available:

  • $view_parameters
  • $ezhttp_hasvariable
  • $module_result.view_parameters
  • $module_result
  • $ezhttp_hasvariable
  • $node
  • $oject
  • $comment
  • $redirect_uri

So even if I pass the parameters in the URL I can not retrieve them.

Is there a way to have a button that returns to the previous page?

Modified on Thursday 16 December 2010 10:03:46 am by Pascal France

Thursday 16 December 2010 10:01:54 am

The tpl variable $canEdit is set in the extension/comments/module/comment/edit.php.(line 41)

$canEdit = false;
$canEditResult = ezcomPermission::hasAccessToFunction( 'edit', $contentObject, $languageCode, $comment, null, $contentNode );
$canEdit = $canEditResult['result'];
$tpl->setVariable( 'can_edit', $canEdit );

If you want this variable in comment_item.tpl you can override it and add a fetch permission at the top of the tpl file.

Thursday 16 December 2010 10:41:30 am

Hi Daisy,

And thanks for your help.

In comment_item.tpl there are already, by default, a «can_edit» and a «can_detele» fetch. But they always return «false» .

In comment_item.tpl the only variables that change according to the permissions of the user are "$can_self_edit" and "$can_self_delete".

The problem is that you can be a user logged in with permission can_self_edit and not have the right to edit the comment of another user.
It seems that this case can not be taken into account in comment_item.tpl

Modified on Thursday 16 December 2010 10:42:12 am by Pascal France

Thursday 16 December 2010 11:34:29 am

I don't really understand what you want to do if the user can't edit the comment there's no edit button and if he can there's one.

Have you an example to illustrate your situation?

Modified on Thursday 16 December 2010 11:51:32 am by Daisy Radix Leroy

Thursday 16 December 2010 11:59:08 am

Daisy, I sent you a private mail (from here this page

Friday 17 December 2010 11:48:31 am

I explain again the context:

By default, the extension ezcomments displays the links "Edit" and "Delete" at the bottom of all comments regardless of the specific rights of the user.

My original question (see my first post) was: how to display the links "Edit" and "Delete" only if the user has the right to edit and/or delete the comment ?

Daisy founded the solution:

We have to replace (in comment_item.tpl):

<div class="ezcom-comment-tool">
                    {if or( $can_edit, $can_self_edit )}
                        {if and( $can_self_edit, not( $can_edit ) )}
                            {def $displayAttribute=$user_display_limit_class}
                            {def $displayAttribute=''}
                            <a href={concat( '/comment/edit/', $ )|ezurl}>{'Edit'|i18n('ezcomments/comment/view')}</a>
                        {undef $displayAttribute}
                    {if or( $can_delete, $can_self_delete )}
                        {if and( $can_self_delete, not( $can_delete ) )}
                            {def $displayAttribute=$user_display_limit_class}
                            {def $displayAttribute=''}
                        <span {$displayAttribute}>
                            <a href={concat( '/comment/delete/',$ )|ezurl}>
                        {undef $displayAttribute}


{if eq( $current_user.contentobject_id, $comment.user_id )}
                  <span {$displayAttribute}>
                     <a href={concat( '/comment/edit/', $ )|ezurl}>{'Edit'|i18n('ezcomments/comment/view')}</a>  
                     <a href={concat( '/comment/delete/',$ )|ezurl}>{'Delete'|i18n('ezcomments/comment/view')}</a>
                  {undef $displayAttribute}

Like that, the «Edit» and «Delete» buttons are only shown if the logged in user is the owner of the comment too.

More over, this solution avoids to solve the problem I described in my 2de post of this thread.

Modified on Friday 17 December 2010 11:55:52 am by Pascal France

Friday 21 January 2011 11:11:18 am

Pascal, for the 1st issue, have you tried to configure it like this?

Go to administrator user interface, in the user role interface -> click 'add policy' -> select module 'comment' and function 'edit' -> click 'grant limited access' -> select 'Self' in CommentCreator.


(Sorry for the late reply)

Friday 21 January 2011 11:35:14 am

Just one note for 2nd issue: since comment edit view is not like ezpublish object edit view, the parameters in object are not available. And there is no object/node parameter here at all. But you can retrive them manually via comment id, see modules/comment/edit.php where there is example.

(Of course if 1st is solved, you don't need to think about 2nd).


You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from