Answers.Body: <blockquote>
    <p>Is there a way to create custom twig tags?</p>
  </blockquote>
  
  <p>Sure.  You can look in <code>craft/app/etc/templating/twigextensions/</code> to see how Craft creates it's own <a href="http://buildwithcraft.com/docs/templating/tags" rel="nofollow">custom Twig tags</a>, which is how a plugin would do it using the <a href="http://buildwithcraft.com/docs/plugins/hooks-reference#addTwigExtension" rel="nofollow">addTwigExtension</a> hook.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-12-09T17:19:24.087Z
Answers.LastActivityDate: 2014-12-09T17:19:24.087Z
Answers.UserDisplayName: Brad Bell
Body: <p>I'm working on a site with a very complex permissions structure (based on groups, dates, dynamic overrides etc). I've written a custom permissions plugin to handle this in a centralized fashion.</p>
  
  <p>In this plugin I've exposed some of the functionality through twig variables:</p>
  
  <pre><code>{{ craft.permissions.require('update','entry.projects', project.id) }}
  </code></pre>
  
  <p>This function is similar to the {% requireLogin %} where it performs redirects and stops craft processing etc if it fails the permissions check.</p>
  
  <p>I need to somehow execute this as a twig tag so that I can place it outside the {% block content %} tags.</p>
  
  <p>Is there a way to create custom twig tags?</p>
  
  <hr>
  
  <p>Alternatively; 
  as a work around I'm using the 'if' tag which is a bit messy:</p>
  
  <pre><code>{% if craft.permissions.require('update','entry.projects', project.id) %}{% endif %}
  </code></pre>
  
  <p>A different tag dedicated to running functions could be useful in the next release, eg:</p>
  
  <pre><code>{% exec craft.permissions.require('update','entry.projects', project.id) %}
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-12-09T21:50:49.953Z
Comments.Text: You may also want to look at Twig's [`do` tag](http://twig.sensiolabs.org/doc/tags/do.html)... It basically just executes a statement without returning anything.
Comments.UserDisplayName: Lindsey D
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-12-10T08:03:27.960Z
Comments.Text: awesome thanks mate
Comments.UserDisplayName: Jered Masters
Tags: <templating><tags>
Title: Custom Twig Tags
ThreadText: # Custom Twig Tags
  
  (Asked by: username_0 on 2014-12-09)
  
  I'm working on a site with a very complex permissions structure (based on groups, dates, dynamic overrides etc). I've written a custom permissions plugin to handle this in a centralized fashion.
  
  In this plugin I've exposed some of the functionality through twig variables:
  
  ```
  {{ craft.permissions.require('update','entry.projects', project.id) }}
  
  ```
  
  This function is similar to the {% requireLogin %} where it performs redirects and stops craft processing etc if it fails the permissions check.
  
  I need to somehow execute this as a twig tag so that I can place it outside the {% block content %} tags.
  
  Is there a way to create custom twig tags?
  
  ---
  
  Alternatively;
  as a work around I'm using the 'if' tag which is a bit messy:
  
  ```
  {% if craft.permissions.require('update','entry.projects', project.id) %}{% endif %}
  
  ```
  
  A different tag dedicated to running functions could be useful in the next release, eg:
  
  ```
  {% exec craft.permissions.require('update','entry.projects', project.id) %}
  
  ```
  
  **Tags:** templating, tags
  
  > **Comments:**
  > **username_1**: You may also want to look at Twig's [`do` tag](http://twig.sensiolabs.org/doc/tags/do.html)... It basically just executes a statement without returning anything.  
  > **username_0**: awesome thanks mate  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2014-12-09. Score: 3 | Accepted answer
  
  > Is there a way to create custom twig tags?
  
  Sure. You can look in `craft/app/etc/templating/twigextensions/` to see how Craft creates it's own [custom Twig tags](http://buildwithcraft.com/docs/templating/tags), which is how a plugin would do it using the [addTwigExtension](http://buildwithcraft.com/docs/plugins/hooks-reference#addTwigExtension) hook.
  
  
  ---
  
  