<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>

CC BY-SA 3.0
2016-02-03T14:42:00.230Z
Nice! Didn't know that, works perfectly. Thanks Brandon!
ctigelaar
CC BY-SA 3.0
2016-02-03T14:37:47.513Z
2016-02-03T14:37:47.513Z
Brandon Kelly
<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>

<templating><plugins><control-panel>
Twig url() function returns CP path when called from plugin
# 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 Brandon!  

---

