Answers.Body: <p>I'm not aware of this being possible. The control panel uses a different template path than the front end. This makes plugin templates generally inaccessible. One possible option is to create a template variable that runs a macro or renders a template on behalf of the user. Something like:</p>
  
  <p><code>{{ craft.pluginHandle.macro(arguments) }}</code></p>
  
  <p>You will need to make sure that the template path is set to the Control Panel so that your macro can be found, and that it's set back afterwards. At the start of the function set this:</p>
  
  <p><code>craft()-&gt;path-&gt;setTemplatesPath(craft()-&gt;path-&gt;getCpTemplatesPath())</code></p>
  
  <p>Then when you are done rendering your macro (preferably to a variable to return later), you set it back:</p>
  
  <p><code>craft()-&gt;path-&gt;setTemplatesPath(craft()-&gt;path-&gt;getSiteTemplatesPath())</code></p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-23T01:41:01.500Z
Answers.Text: So, I just attempted this, but renderMacro seems to only have access to the front end template path, even when doing it through template vars. :-/
Answers.UserDisplayName: Christopher Mancini
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-23T02:04:28.407Z
Answers.Text: My bad. I added a couple commands that will allow the plugin to find the macro template for rendering.
Answers.UserDisplayName: Bryan Redeagle
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-22T21:04:53.050Z
Answers.LastActivityDate: 2014-06-23T02:02:59.277Z
Answers.LastEditDate: 2014-06-23T02:02:59.277Z
Answers.UserDisplayName: Bryan Redeagle
Body: <p>I have a plugin that I am writing and I want to make available a macro that can be used within the front end sites templates. What is the best way to do that?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-06-22T19:14:24.407Z
Comments.Text: Do you need to specify it as a macro or would a Twig function work, too?
Comments.UserDisplayName: Victor
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-06-22T20:01:45.760Z
Comments.Text: What are you trying to do with the macro? What purpose is it serving?
Comments.UserDisplayName: Bryan Redeagle
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-06-22T20:29:25.370Z
Comments.Text: @VictorIn, twig functions could probably work, however it doesn't feel right having several lines of markup within PHP classes....
Comments.UserDisplayName: Christopher Mancini
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-06-22T20:31:31.797Z
Comments.Text: @ChrisMancini Can you add an example of what you are trying to do to your question?
Comments.UserDisplayName: Victor
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-06-22T20:31:33.270Z
Comments.Text: @BryanRedeagle, I see many use cases for this sort of functionality, but my first use case is for forms that need to be submitted that are core to my plugins functionality. The end user could invoke the macro passing through a few required / optional parameters and it renders accordingly. Similar to how we can use Craft form macros within our plugins CP.
Comments.UserDisplayName: Christopher Mancini
Tags: <templating><plugin-development>
Title: How can I create a template macro within my plugin for use within front end templates?
ThreadText: # How can I create a template macro within my plugin for use within front end templates?
  
  (Asked by: username_0 on 2014-06-22)
  
  I have a plugin that I am writing and I want to make available a macro that can be used within the front end sites templates. What is the best way to do that?
  
  **Tags:** templating, plugin-development
  
  > **Comments:**
  > **username_1**: Do you need to specify it as a macro or would a Twig function work, too?  
  > **username_2**: What are you trying to do with the macro? What purpose is it serving?  
  > **username_0**: @VictorIn, twig functions could probably work, however it doesn't feel right having several lines of markup within PHP classes....  
  > **username_1**: @ChrisMancini Can you add an example of what you are trying to do to your question?  
  > **username_0**: @username_2, I see many use cases for this sort of functionality, but my first use case is for forms that need to be submitted that are core to my plugins functionality. The end user could invoke the macro passing through a few required / optional parameters and it renders accordingly. Similar to how we can use Craft form macros within our plugins CP.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2014-06-22. Score: 4 | Accepted answer
  
  I'm not aware of this being possible. The control panel uses a different template path than the front end. This makes plugin templates generally inaccessible. One possible option is to create a template variable that runs a macro or renders a template on behalf of the user. Something like:
  
  `{{ craft.pluginHandle.macro(arguments) }}`
  
  You will need to make sure that the template path is set to the Control Panel so that your macro can be found, and that it's set back afterwards. At the start of the function set this:
  
  `craft()->path->setTemplatesPath(craft()->path->getCpTemplatesPath())`
  
  Then when you are done rendering your macro (preferably to a variable to return later), you set it back:
  
  `craft()->path->setTemplatesPath(craft()->path->getSiteTemplatesPath())`
  
  > **Comments:**
  > **username_0**: So, I just attempted this, but renderMacro seems to only have access to the front end template path, even when doing it through template vars. :-/  
  > **username_2**: My bad. I added a couple commands that will allow the plugin to find the macro template for rendering.  
  
  ---
  
  