Skip to content

Instantly share code, notes, and snippets.

@dajare
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dajare/335be73018d93b069328 to your computer and use it in GitHub Desktop.
Save dajare/335be73018d93b069328 to your computer and use it in GitHub Desktop.
Frontend links for page editing in backend

Frontend links for page editing in backend

This "tutorial" is based on a forum thread started by Ormente with responses from Martijn. Consult that thread for further discussion.

It's often useful to be able to go directly to the backend to edit a page while browsing your site. You can make such a link in Wolf by copying this code into a snippet (filter set to -none-):

<?php
<span class="c1">// Check there's a user session</span>
<span class="nx">AuthUser</span><span class="o">::</span><span class="na">load</span><span class="p">();</span>

<span class="c1">// Check the user is logged in and has page_edit permission.</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">AuthUser</span><span class="o">::</span><span class="na">isLoggedIn</span><span class="p">()</span> <span class="o">&amp;&amp;</span> <span class="nx">AuthUser</span><span class="o">::</span><span class="na">hasPermission</span><span class="p">(</span><span class="s1">'page_edit'</span><span class="p">))</span> <span class="p">{</span>

    <span class="nv">$url</span> <span class="o">=</span> <span class="nx">BASE_URL</span><span class="o">.</span><span class="s1">'admin/page/edit/'</span><span class="o">.</span><span class="nv">$this</span><span class="o">-&gt;</span><span class="na">id</span><span class="p">();</span>
    <span class="k">echo</span> <span class="s1">'&lt;span class="quickedit"&gt;&lt;a href="'</span><span class="o">.</span><span class="nv">$url</span><span class="o">.</span><span class="s1">'"&gt;Edit this page&lt;/a&gt;&lt;/span&gt;'</span><span class="p">;</span>
<span class="p">}</span>

?>

Save the snippet as 'quickedit', and call the snippet in your layout with:

<?php $this->includeSnippet('quickedit'); ?>

where you want your edit link to appear.

You could also:

  • add some CSS rules for the ''.quickedit'' class;
  • use usernames instead of roles (see the original forum thread);
  • add another condition to limit the appearance of the "Edit this page" link to certain branches of your site;
  • etc.!

Thanks to Ormente for this suggestion!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment