How do I fix getTemplatesPath() / setTemplatesPath() deprecation errors? After updating to Craft 2.6.2778, my plugin is causing these deprecation errors:

PathService::getTemplatesPath() has been deprecated. Use TemplatesService::getTemplatesPath() or TemplatesService::getTemplateMode() instead.
PathService::setTemplatesPath() has been deprecated. Use TemplatesService::setTemplatesPath() or TemplatesService::setTemplateMode() instead.

How do I fix these?
PathsService::getTemplatesPath() and setTemplatesPath() were deprecated in Craft 2.6.2778. They were commonly used by Craft and plugins to render front-end templates from the Control Panel (or vise-versa).

We realized that there were cases where simply changing the root templates path was insufficient to emulate front-end requests in the CP, though. For example, if defaultTemplateExtensions was being overridden to:



'defaultTemplateExtensions' =&gt; array('htm'),


and the CP was trying to find a “test” template which was supposed to resolve to test.htm, a CP request would not actually be able to find the template, because CP requests are only looking for templates that end in .twig and .html.

So in 2.6.2778 we’ve resolved this with “template modes”, which provide an explicit way to tell Craft to render a front-end template vs. a CP template, rather than simply telling it to use a different base template directory.

Updating your plugin code is pretty simple. Just change things like this:

$oldPath = craft()-&gt;path-&gt;getTemplatesPath();
craft()-&gt;path-&gt;setTemplatesPath(craft()-&gt;path-&gt;getSiteTemplatesPath());

// ...

craft()-&gt;path-&gt;setTemplatesPath($oldPath);


to this:

$oldMode = craft()-&gt;templates-&gt;getTemplateMode();
craft()-&gt;templates-&gt;setTemplateMode(TemplateMode::Site);

// ...

craft()-&gt;templates-&gt;setTemplateMode($oldMode);