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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

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


Go to End


3 Posts   870 Views

Avatar
Bereusei

Community Member, 96 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, 5523 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, 96 Posts

10 January 2012 at 6:10am

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