Custom modules - edit and delete for content owner only

I’ve got a custom module and am trying to set up the edit and delete functions on the detail layout to ONLY be available to the logged in content owner.

I have tried wrapping the edit/delete buttons and testing if the user is logged in and that works but the edit button displays for ALL logged in users, not just the content owner.

I thought maybe I could create 2 detail layouts - one showing the edit and delete function for the content owner and one for everyone else but not sure how to edit the link.

eg

<a  href="{{this['Url']}}"> See more</a> - links to public layout (no edit button)
<a  href="{{this['Url' | with special layout]}}">
See more</a> - links to content owner layout with edit button

alternatively is there a way to test if the logged in user is the content owner?

Yes, items have the property of CreatedByMemberId which will have the creators CRM ID.
So like you were doing to show the buttons if logged in, you can additionally check for a matching member ID.

Something like:

{% if this.CreatedByMemberId == request.currentmember.id %}
<!-- YOUR BUTTONS HERE -->
{% endif %}
2 Likes

Brilliant!. Thankyou :slight_smile: That works perfectly.