Contribute to Docs Contribute to Docs

Create links to edit content

When logged-in and browsing the site, it is conventient for content editors to directly open the post or page in the Manager for editing.

This can be achieved simply by including the following partial view either to your _Layout.cshtml or to your Page.cshtml and Post.cshtml razor pages.

_ShowEditLinkPartial.cshtml

@using Microsoft.AspNetCore.Authorization
@inject IAuthorizationService Auth
@* Show an 'Edit' button on every page and every post to authorized users *@
<div class="position-relative">
    @if (WebApp.CurrentPage != null && (await Auth.AuthorizeAsync(User, Piranha.Manager.Permission.Pages)).Succeeded)
    {
        <div>
            <a target="_blank" href="~/manager/page/edit/@WebApp.CurrentPage.Id" class="btn btn-sm btn-primary">Edit</a>
        </div>
    }
    @if (WebApp.CurrentPost != null && (await Auth.AuthorizeAsync(User, Piranha.Manager.Permission.Posts)).Succeeded)
    {
        <div>
            <a target="_blank" href="~/manager/post/edit/@WebApp.CurrentPost.Id" class="btn btn-sm btn-primary">Edit</a>
        </div>
    }
</div>

You'll have to modify this partial view to meet your requirements (e.g. styling and position of the buttons).

To make this even more comfortable, you might consider adding a Login page to your site, as described in the tutorial Securing Pages.