Jump to:

7939 Posts in 1472 Topics by 944 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Chance the CSS, if($Author == currentMember)

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1
Go to End
Author Topic: 328 Views
  • Bereusei
    Avatar
    Community Member
    94 Posts

    Chance the CSS, if($Author == currentMember) Link to this post

    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.

  • Willr
    Avatar
    Forum Moderator
    5462 Posts

    Re: Chance the CSS, if($Author == currentMember) Link to this post

    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;
    }

  • Bereusei
    Avatar
    Community Member
    94 Posts

    Re: Chance the CSS, if($Author == currentMember) Link to this post

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

    328 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.