Answers.Body: <p>No, the <code>isEditable</code> property isn't supported for Global Sets.</p>
  
  <p>The confusing thing is that the <a href="https://buildwithcraft.com/classreference/models/GlobalSetModel" rel="nofollow"><code>GlobalSetModel</code></a> class does actually have an <a href="https://buildwithcraft.com/classreference/models/BaseElementModel#isEditable-detail" rel="nofollow"><code>isEditable</code></a> property, however it will always return <code>false</code>. The reason is that this property is inherited from the <code>BaseElementModel</code> class, where it will return <code>false</code> <em>unless the element type overrides it to (potentially) return something else</em>. An example of the latter is the <code>EntryModel</code> class, which also inherits <code>BaseElementModel</code> but overrides  <code>isEditable</code> <a href="https://buildwithcraft.com/classreference/models/EntryModel#isEditable-detail" rel="nofollow">to test if the current user is allowed to edit the entry</a>.</p>
  
  <p>It'd be interesting to hear P&amp;T's reasoning for not "enabling" <code>isEditable</code> for Global Sets, although to be honest – needing to give users the ability to edit global variables from the frontend sounds like an edge case at best, and probably not a very good idea.</p>
  
  <p><em>On that note, my best advice for a workaround would be to simply use a Single instead of a Global Set.</em></p>
  
  <p>However, if you need/want to use a Global Set, you can easily work around the issue by creating a custom plugin exposing a <code>isGlobalSetEditable</code> template variable method. Something like this should work:</p>
  
  <pre><code>public function isGlobalSetEditable(GlobalSetModel $globalSet)
  {
      return craft()-&gt;userSession-&gt;checkPermission('editGlobalSet:'.$globalSet-&gt;id);
  }
  </code></pre>
  
  <p>In your template, you could then do something like this:</p>
  
  <pre><code>{% if craft.myPlugin.isGlobalSetEditable(headline) %}
      &lt;a href="{{ headline.cpEditUrl }}"&gt;Edit me&lt;/a&gt;
  {% endif %}
  </code></pre>
  
  <p>If you're not familiar with plugin development, I'd advice you to check out the <a href="http://buildwithcraft.com/docs/plugins/introduction" rel="nofollow">official docs on the subject</a>, and to download the excellent <a href="https://github.com/lindseydiloreto/craft-businesslogic" rel="nofollow">Business Logic Plugin</a> as a starting point – it even has a Variable class where the above <code>isGlobalSetEditable</code> method could be dropped right in.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-11-02T20:09:36.750Z
Answers.LastActivityDate: 2015-11-02T20:09:36.750Z
Answers.UserDisplayName: Mats Mikkel Rummelhoff
Answers.Body: <p><code>isEditable()</code> would be a method of the content model, not of a field. Unfortunately, this is currently only useful for <em><a href="https://buildwithcraft.com/classreference/models/EntryModel#isEditable-detail" rel="nofollow">EntryModel</a></em> objects; It is not presently implemented for <em>GlobalSetModel</em> objects, so using <code>.isEditable</code> on a global set will always <a href="https://buildwithcraft.com/classreference/models/BaseElementModel#isEditable-detail" rel="nofollow">return <code>false</code></a>.</p>
  
  <p>However, you could use the <a href="https://buildwithcraft.com/classreference/models/UserModel#can-detail" rel="nofollow"><code>.can()</code></a> method on a user, and check for the permission <code>'editglobalset:X'</code> (where <em>X</em> is the ID of your Global Set element).</p>
  
  <p>For example — assuming <code>header</code> is a <em>GlobalSetObject</em> you have fetched elsewhere in your template):</p>
  
  <pre><code>{% if currentUser and currentUser.can('editglobalset:' ~ header.id) %}
  ...
  {% endif %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-11-02T20:32:27.837Z
Answers.Text: Good call on the `currentUser.can` approach – definitely easier than creating a custom plugin!
Answers.UserDisplayName: Mats Mikkel Rummelhoff
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-11-02T20:20:48.670Z
Answers.LastActivityDate: 2015-11-02T20:33:09.263Z
Answers.LastEditDate: 2015-11-02T20:33:09.263Z
Answers.UserDisplayName: Michael Rog
Body: <p>I have a <code>headline</code> global.</p>
  
  <p>I am trying to see if <code>headline</code> is editable by using this code block, but it is not working.</p>
  
  <p>Can I use <code>isEditable()</code> with my <code>headline</code> global?</p>
  
  <pre><code>{% if headline.isEditable() %}
      &lt;div class="admin-edit-button-wrapper"&gt;
          &lt;a href="{{ headline.cpEditUrl }}" class="admin-edit-button"&gt;Edit Headline&lt;/a&gt;
      &lt;/div&gt;
  {% endif %}
  </code></pre>
  
Tags: <globals>
Title: Can I use isEditable() on a global?
ThreadText: # Can I use isEditable() on a global?
  
  (Asked by: username_0 on 2015-11-02)
  
  I have a `headline` global.
  
  I am trying to see if `headline` is editable by using this code block, but it is not working.
  
  Can I use `isEditable()` with my `headline` global?
  
  ```
  {% if headline.isEditable() %}
      <div class="admin-edit-button-wrapper">
          <a href="{{ headline.cpEditUrl }}" class="admin-edit-button">Edit Headline</a>
      </div>
  {% endif %}
  
  ```
  
  **Tags:** globals
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2015-11-02. Score: 4 | Accepted answer
  
  `isEditable()` would be a method of the content model, not of a field. Unfortunately, this is currently only useful for *[EntryModel](https://buildwithcraft.com/classreference/models/EntryModel#isEditable-detail)* objects; It is not presently implemented for *GlobalSetModel* objects, so using `.isEditable` on a global set will always [return `false`](https://buildwithcraft.com/classreference/models/BaseElementModel#isEditable-detail).
  
  However, you could use the [`.can()`](https://buildwithcraft.com/classreference/models/UserModel#can-detail) method on a user, and check for the permission `'editglobalset:X'` (where *X* is the ID of your Global Set element).
  
  For example — assuming `header` is a *GlobalSetObject* you have fetched elsewhere in your template):
  
  ```
  {% if currentUser and currentUser.can('editglobalset:' ~ header.id) %}
  ...
  {% endif %}
  
  ```
  
  > **Comments:**
  > **username_1**: Good call on the `currentUser.can` approach – definitely easier than creating a custom plugin!  
  
  ---
  
  ### Answer by username_1 on 2015-11-02. Score: 4
  
  No, the `isEditable` property isn't supported for Global Sets.
  
  The confusing thing is that the [`GlobalSetModel`](https://buildwithcraft.com/classreference/models/GlobalSetModel) class does actually have an [`isEditable`](https://buildwithcraft.com/classreference/models/BaseElementModel#isEditable-detail) property, however it will always return `false`. The reason is that this property is inherited from the `BaseElementModel` class, where it will return `false` *unless the element type overrides it to (potentially) return something else*. An example of the latter is the `EntryModel` class, which also inherits `BaseElementModel` but overrides `isEditable` [to test if the current user is allowed to edit the entry](https://buildwithcraft.com/classreference/models/EntryModel#isEditable-detail).
  
  It'd be interesting to hear P&T's reasoning for not "enabling" `isEditable` for Global Sets, although to be honest – needing to give users the ability to edit global variables from the frontend sounds like an edge case at best, and probably not a very good idea.
  
  *On that note, my best advice for a workaround would be to simply use a Single instead of a Global Set.*
  
  However, if you need/want to use a Global Set, you can easily work around the issue by creating a custom plugin exposing a `isGlobalSetEditable` template variable method. Something like this should work:
  
  ```
  public function isGlobalSetEditable(GlobalSetModel $globalSet)
  {
      return craft()->userSession->checkPermission('editGlobalSet:'.$globalSet->id);
  }
  
  ```
  
  In your template, you could then do something like this:
  
  ```
  {% if craft.myPlugin.isGlobalSetEditable(headline) %}
      <a href="{{ headline.cpEditUrl }}">Edit me</a>
  {% endif %}
  
  ```
  
  If you're not familiar with plugin development, I'd advice you to check out the [official docs on the subject](http://buildwithcraft.com/docs/plugins/introduction), and to download the excellent [Business Logic Plugin](https://github.com/lindseydiloreto/craft-businesslogic) as a starting point – it even has a Variable class where the above `isGlobalSetEditable` method could be dropped right in.
  
  
  ---
  
  