Hot answers tagged

14 votes

How can I check from a plugin config file if devMode is enabled?

For those coming here using Craft 3, it's now Craft::$app->getConfig()->general->devMode.
Nate Beaty's user avatar
11 votes
Accepted

Multiple developers working on the same site - Project config issues

Your trouble comes from working in the main branch directly, don't do that. Instead, follow a feature branch workflow where every feature is developed in a dedicated branch. This way, every developer ...
MoritzLost's user avatar
  • 11.2k
9 votes
Accepted

HTML Purifier Config File

Something like this in a .json file should work: { "HTML.SafeIframe": true, "URI.SafeIframeRegexp": "%^(https?:)?//(www\\.youtube(?:-nocookie)?\\.com/embed/)%", &...
Brad Bell's user avatar
  • 67.4k
8 votes
Accepted

How can I check from a plugin config file if devMode is enabled?

It's as simple as if ( craft()->config->get( 'devMode' ) ) { //do stuff }
Luke Pearce's user avatar
  • 3,863
8 votes
Accepted

Craft 3: how can I set dynamic Base URL in sites setting?

So as of Craft CMS 3 RC7, they added a new alias() Twig function. So what you can do is something like this in your general.php: 'aliases' => [ '@basePath' => getenv('CRAFTENV_BASE_PATH'), ...
andrew.welch's user avatar
  • 11.5k
7 votes

How do i get variables from general.php

For Craft 3: Craft::$app->config->general->{var name}
Henry's user avatar
  • 396
7 votes
Accepted

How to remove index.php?p= permanently?

Taken from this answer on Stack Overflow: .htaccess mod_rewrite: rewriting querystring to path <IfModule mod_rewrite.c> RewriteEngine On # Remove index.php RewriteCond %{...
Alex Roper's user avatar
  • 2,632
7 votes

Upload file size limits to 256MB

When determining the maximum upload file size, Craft first takes the php.ini file upload_max_filesize, post_max_size and memory_limit into account by getting the minimum value and only then applying ...
Brad Bell's user avatar
  • 67.4k
6 votes
Accepted

devMode, phpdotenv variable ignored

It looks like getenv returns a string (or false if the variable is not set, but it is in this case). So you need to cast the string to a boolean value to make it work. However, (bool)'false' gives ...
carlcs's user avatar
  • 36.2k
6 votes

Overriding isSystemOn setting for a single page

I realized there is a simpler solution after stepping away from this issue for a bit. There is one page that still returns a 200 code on a Craft site even when the isSystemOn (or isSystemLive as of ...
John Morton's user avatar
5 votes
Accepted

How can I localize a URL in a plugin?

You can use UrlHelper::getSiteUrl() instead, which does have a $localeId argument, for generating a URL relative to a given locale’s base URL (per the siteUrl config setting). So if your siteUrl ...
Brandon Kelly's user avatar
5 votes
Accepted

Craft can't connect to db.php on live server

The cooldownDuration setting should go in your general.php config file, not in your db.php config file. On your server, is the db on a separate server or is it on the same server? If so, the value for ...
Steve Rowling's user avatar
5 votes
Accepted

Passing JSON to Twig

The answer is to create a custom plugin that will read the json files from the folders in the public directory, parse the json, and pull them into the template. An alternative solution is to use ...
Sam Hernandez's user avatar
4 votes
Accepted

Some paths and settings being ignored in config

You're close! Those config settings are off in no-mans-land right now. If you want them to apply across all of your multi-environment configs, you need to move them into the '*' array like so: ...
Brad Bell's user avatar
  • 67.4k
4 votes

How do i get variables from general.php

It is considered best practice to use the public get methods, so while the Craft 3 answer is correct, you should try to get in the habit of calling the methods. Craft::$app->getConfig()->...
James White's user avatar
  • 1,151
4 votes
Accepted

Cannot remove index.php from URLs either

In this case, the Apache mod_rewrite module wasn't installed, so the <IfModule mod_rewrite.c> block of Craft's default .htaccess file was being skipped not allowing index.php to be rewritten in ...
Brad Bell's user avatar
  • 67.4k
4 votes
Accepted

Can I set an environment var for SMTP mail servers?

Not an easy way to do this in Craft 2, but this is possible in the upcomgin Craft 3 (currently in beta) using craft/config/app.php, which is multi-environment aware.
Brad Bell's user avatar
  • 67.4k
4 votes

Issues upgrading Craft 2 to 3 - Keep seeing Install Screen not Update screen

If you've seeing any install screen instead of an update screen, that means that Craft can connect to the database server specified in craft/config/db.php file, but it either can't find the database ...
Brad Bell's user avatar
  • 67.4k
4 votes

help setting up web root to point to /web

You need to configure your webserver/virtualhost to point to the /web directory. For apache you have DocumentRoot: your_disk_path/web For nginx you have root: your_disk_path/web
dustfeather's user avatar
4 votes
Accepted

Working locally after cloning Craft 3 from Hyperlane

Solved. The config/db.php cloned from Hyperlane refers to different env variable names than those used within my .env file. Changing the names in config/db.php solved the issue. Before: return [ ...
Clive Portman's user avatar
4 votes
Accepted

Invalid Configuration Error in Craft CMS 3 using Nitro 2

This path is on your host machine but this isn't how docker sees things. To Nitro, the location of the folder is /app/web/cpresources. Without going into too much details, I'd recommend going with an ...
Oli's user avatar
  • 7,485
4 votes
Accepted

Project config priority between project config files and database

Question part A. Does the database take precedence or do the project config files take precedence? When Craft loads and there is an inconsistency between both... which setting makes it to the admin ...
MoritzLost's user avatar
  • 11.2k
3 votes

Setting system email address and sender name in multi config

Marion's answer is a workaround for Craft 2, but this has been officially addressed in the upcoming Craft 3: https://github.com/craftcms/cms/issues/840
Brad Bell's user avatar
  • 67.4k
3 votes
Accepted

Setting system email address and sender name in multi config

The testToEmailAddress config setting which Configures Craft to send all system emails to a single email address (or multiple email addresses), for testing purposes. sounds like the one you are ...
Marion Newlevant's user avatar
3 votes
Accepted

Prevent direct access to a web page except redirect

Add a Preparse field to the entry type you're posting to and make it generate a random string on entry save. Then make the Guest Entries plugin redirect to a URL with that Preparse field's value in ...
carlcs's user avatar
  • 36.2k
3 votes

General Settings > logo in the template

For version 3.x.x. Check and get rebrand logo: {% if craft.rebrand.isLogoUploaded() %} <img width="{{ craft.rebrand.getLogo().size[0] }}" height="{{ craft.rebrand.getLogo().size[1] }}" src="{{...
William Isted's user avatar
3 votes

Set return URL after password is set

Solved this by creating the Set Password form in a template with the correct return setting it's path with setPasswordPath setting a path for setPasswordSuccessPath to catch forgot password ...
Christy Collins's user avatar
3 votes

siteUrl not updating

When setting siteUrl in config.php, it overrides the "Site URL" setting in CP → Settings → General. It doesn't show the settings in that field. This is being overridden by the siteUrl config ...
carlcs's user avatar
  • 36.2k
3 votes
Accepted

Will a change to verificationCodeDuration be updated retrospectively?

If you check UsersService->isVerificationCodeValidForUser(), you can see that it's taking the current date/time and subtracting the verificationCodeDuration config setting value, then comparing that ...
Brad Bell's user avatar
  • 67.4k
3 votes
Accepted

contactform.php messing up site

The problem is the ... in your contactform.php file. The docs use it because they assume you might have some other valid config settings you want to include in that config file, but it's not real ...
Brad Bell's user avatar
  • 67.4k

Only top scored, non community-wiki answers of a minimum length are eligible