April 29, 2008

Inline Editing Controls in Expression Engine

This is another post about interfacing with the control panel in Expression Engine and a number of people have requested it after my previous post (Creating an Admin Bar for Expression Engine).

It’s actually not too complicated. I’ll help you get set-up with some syntax for the blog homepage and your blog comments page. Let’s get started.

Skip to syntax →

First things first

In order to just show this to our Super Admin’s we need to get the logged_in_group_id variable that tells us what group the currently logged in user is in. You may remember we used a similar variable (group_id) in the previous example for the admin bar. Since we’re going to use this variable within other tags (the weblog:entries, and comment:entries tags) we need to specify that we want to learn about the logged in user.

Linking to the CP

Next, we need to figure out our link syntax. The control panel uses a pretty simple syntax that isn’t really documented anywhere, but easy to learn.

To edit a specific post, we need this URL:

/(name of your system folder)/index.php?C=edit&M=edit_entry&weblog_id=(weblog_id of the entry)&entry_id=(entry_id for the post)

To close a specific comment, we need this URL:

/(name of your system folder)/index.php?C=edit&M=change_status&weblog_id=(weblog_id of the entry)&entry_id=(entry_id for the post)&comment_id=(id of the comment you’re closing)&status=close

Generating the URL

Lastly, we need to find the variables to give us these URLs. Here’s what you’ll actually be using for your links.

For “Edit this post”:

  • {weblog_id} - get the id of the weblog for the current post
  • {entry_id} - get the entry id of the current post

For “Close this comment”:

  • {weblog_id} - get the id of the weblog for the current post
  • {entry_id} - get the entry id of the current post
  • {comment_id} - get the id of the current comment

Final Syntax

Now let’s put it all together!

Edit this entry example:

{exp:weblog:entries}

{if logged_in_group_id == 1}

<a href="/system/index.php?C=edit&M=edit_entry&weblog_id={weblog_id}&entry_id={entry_id}">Edit this entry</a>

{/if}

{/exp:weblog:entries}

Close this comment example:

{exp:comment:entries}

{if logged_in_group_id == 1}

<a href="/system/index.php?C=edit&M=change_status&weblog_id={weblog_id}&entry_id={entry_id}&
comment_id={comment_id}&status=close">Close comment</a>

{/if}

{/exp:comment:entries}

Make your own

The possibilities of inline editing are nearly infinite. To create your own custom solutions, here’s what I recommend.

  1. Visit the area that you want to link to in the control panel
  2. Analyze the URL of where you are in the CP
  3. Determine which variables in the URL need to be filled in dynamically
  4. Search the documentation for the variable you need. Hint: the CP’s variables are typically the same variable names you’ll use to generate the content (weblog_id = {weblog_id}).
  5. Add conditionals that you need to limit access to these links. Generally, logged_in_group_id is what you’ll use, but there may be other functionality you need.
  6. Assemble your URL and test it on an obscure page or a test template. If it works how you need it to, then push it live.

I hope this helps anyone who is looking to interface inline with the Expression Engine’s control panel. Leave your thoughts, comments, suggestions, and conspiracy theories in the comments below.

generic avatar
Sergio Ruiz | April 29, 2008

Fantastic! Your EE tutorials are very useful Josh :)

Thanks man.

generic avatar
| May 01, 2008

Thanks Sergio!

Glad you enjoyed it!

generic avatar
| May 01, 2008

This is another test

Leave Your Thoughts:
Comment with Open ID:
Or, enter your information below: