Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

Moderators: martimiz, UncleCheese, Sean, biapar, Willr, Ingo, swaiba, simon_w

Chance the CSS, if($Author == currentMember)


Reply


3 Posts   458 Views

Avatar
Bereusei

Community Member, 94 Posts

8 January 2012 at 6:11am

Hallo guys,

I have a simple DOM-table at the frontend, where the Author of the entry is shown:

<table class="entries">
<tr id="Entry{$ID}">
<td>$Date.format(d.m.Y)</td>
<td>$Content</td>
<td>$Author.Name</td>
</tr>
</table>

Now I want something like this:
if($Author == $currentMember)
{
$('table.entries tr').css('background-color', 'red');
}

I really don´t know how I can do this or whether it is possible at all.
Hope somebody can help.

I hope this is the right forum for this question, otherwise please replace this post.

Avatar
Willr

Forum Moderator, 5513 Posts

9 January 2012 at 7:01pm

I'm pretty sure in the current template engine (2.*) it doesn't support things like Author = CurrentMember. The value must be a static value such as a 'string' or integer.

One way around this is to add a function to your dataobject which returns true if the member is author. That way you keep your logic inside the model.

function IsAuthor() {
$member = Member::currentUserID();

return ($member && $member->ID == $this->AuthorID);

..

<tr id="Entry{$ID}" <% if IsAuthor %>class="authored"<% end_if %>>

..

.authored {
background: #f00;
}

Avatar
Bereusei

Community Member, 94 Posts

10 January 2012 at 6:10am

Thanks Willr, this solution works perfect! This is, what I was looking for.