Answers.Body: <p>Right, <code>url()</code> (and <a href="https://craftcms.com/classreference/helpers/UrlHelper#getUrl-detail">UrlHelper::getUrl()</a>, which <code>url()</code> maps to) will create a URL to either a front-end page or a CP page, depending on where it is being called from.</p>
  
  <p>If you want to get a front-end URL from a CP request, you can use <code>siteUrl()</code> instead. (You can also get a CP URL from a front-end request via <code>cpUrl()</code>.)</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-02-03T14:42:00.230Z
Answers.Text: Nice! Didn't know that, works perfectly. Thanks Brandon!
Answers.UserDisplayName: ctigelaar
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-02-03T14:37:47.513Z
Answers.LastActivityDate: 2016-02-03T14:37:47.513Z
Answers.UserDisplayName: Brandon Kelly
Body: <p>I'm using <a href="https://github.com/objectivehtml/Postmaster-for-Craft-CMS" rel="nofollow">Postmaster</a> plugin to handle my e-mails using a custom service for SendGrid. In my templates I use Twig's <code>url()</code> function to create my URLs.</p>
  
  <p>When they are sent by Postmaster, <code>craft-&gt;template-&gt;render()</code> method creates a Control Panel url instead of a normal front-end URL. Which results in URL's not found when clicked in the e-mail.</p>
  
  <p>Is this normal behaviour when the <code>render()</code> method is called from the control panel? Or can I override this in Twig templating maybe? The <a href="https://craftcms.com/docs/templating/functions#url" rel="nofollow">Craft docs</a> don't mention it.</p>
  
  <p>In the meantime I can create my URL's using {{ siteUrl }}, but I'm wondering if I'm missing something here.</p>
  
Tags: <templating><plugins><control-panel>
Title: Twig url() function returns CP path when called from plugin
ThreadText: # Twig url() function returns CP path when called from plugin
  
  (Asked by: username_0 on 2016-02-03)
  
  I'm using [Postmaster](https://github.com/objectivehtml/Postmaster-for-Craft-CMS) plugin to handle my e-mails using a custom service for SendGrid. In my templates I use Twig's `url()` function to create my URLs.
  
  When they are sent by Postmaster, `craft->template->render()` method creates a Control Panel url instead of a normal front-end URL. Which results in URL's not found when clicked in the e-mail.
  
  Is this normal behaviour when the `render()` method is called from the control panel? Or can I override this in Twig templating maybe? The [Craft docs](https://craftcms.com/docs/templating/functions#url) don't mention it.
  
  In the meantime I can create my URL's using {{ siteUrl }}, but I'm wondering if I'm missing something here.
  
  **Tags:** templating, plugins, control-panel
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-02-03. Score: 7 | Accepted answer
  
  Right, `url()` (and [UrlHelper::getUrl()](https://craftcms.com/classreference/helpers/UrlHelper#getUrl-detail), which `url()` maps to) will create a URL to either a front-end page or a CP page, depending on where it is being called from.
  
  If you want to get a front-end URL from a CP request, you can use `siteUrl()` instead. (You can also get a CP URL from a front-end request via `cpUrl()`.)
  
  > **Comments:**
  > **username_0**: Nice! Didn't know that, works perfectly. Thanks username_1!  
  
  ---
  
  