Hi, searched a lot, can’t find solution. I would like to add EDIT links to frontend. It’s very necessary feature, as many times I can notice something wrong in certain page, and it’s much easier to edit when I am already at that page, rather that open panel and look for it there.
So, what I need to do, is to show some code on frontend, if I am logged in. Something like:
I use this on a Kirby 2 site which i think should still fly …
<?php if ($user = $site->user() and $user->hasPanelAccess()): ?>
<!-- your link -->
<?php endif; ?>
I think theres an easier way now populate the URL for the page in the panel, but I cant quite recall the exact thing. Try looking up panel() in the reference.
Good stuff, ill give you another tip for it… this is fine for single pages but what if you want edit pages listed out on something like a blog list page?
Snippets to the rescue! if you put the link in a snippet and pass a parameter to it, you can use it in a loop…
Yep, thats better but you should probably also check that they have panel access, as described above, since its possible to have users that are not allowed to login to the panel, but can log into the front end (for things like protected pages etc).
I actually was looking for the way to edit child pages (like article or project in a list). For examlpe on frontpage I have featured sponsors, and this is working:
I would still go with the snippet idea i described above, since it keeps the code for the link in one place, rather then dotted around your templates and other snippets. Easier maintenance
Only there is one thing: after turning on cache, looks like this <?php if ($kirby->user()): ?> rule is only working on children pages. On parents doesn’t show anything.
I’m not sure how the protected stuff works out with caching turned on. I Imagine the non-logged in copy of the page is in the cache and you need to flush it, or youve used the link code in a loop that only applys to children. Are you sure it worked all over before enabling the cache?
I’m afraid i dont know a huge amount about the caching. you could at least delete the cache folder and see after logging in and see if it works, at least then you know its the cache.
Other then excluding those pages from the cache, im not sure how to solve it.