What's the deal with Deno? We talk with a major contributor to find out. Listen now.

Hot answers tagged

21

In Craft 3 this is now {{ craft.app.request.absoluteUrl }} — for those who land here from a search and want to avoid using the deprecation notice to update it!


18

Craft 3 In Craft 3 this is now {{ craft.app.request.absoluteUrl }} — for those who land here from a search and want to avoid using the deprecation notice to update it! (see answer from @natebeaty) And in case you are looking for more options like {{ craft.app.request.pathInfo }} to get current url path, look up the Craft 3 Craft Web Request Class Craft 2 ...


12

One method is using something like the following in your general.php file. Using this method the config settings will take on the scheme of the request being made. I've set both the siteUrl and example environmentVariables below: <?php // Ensure our urls have the right scheme define('URI_SCHEME', ( isset($_SERVER['HTTPS'] ) ) ? "https://" : "http://" ...


12

The siteUrl global variable is actually set by calling url() without passing anything into it1, so if you're asking about the difference between siteUrl and url() without passing a path to it, you will always get the exact same result. The only difference is that it will be ever so slightly more efficient to use siteUrl since that is a variable that has ...


9

I solved the problem and am writing it down for future people encountering the same problem. Add the following configuration to the your craft/config/general.php config file: 'omitScriptNameInUrls' => true URLs will start to work fine.


7

In your Control Panel, go to Settings > General. Then set your Site URL to {siteUrl}. This will parse out the siteUrl environment variable. For more information, see this thread...


6

Edited I just learned this, but as of Craft 2.4, there's a kebab filter which you can use here. This would probably give you the effect you're after, where the string "two words" would become "two-words", and punctuation characters are dropped by default. You could use this like so: <li><a href="{{ siteUrl }}tags/{{ tag.title | kebab }}">{{ ...


6

You're asking a loaded question. When you mention memory, how exactly are you measuring that? Site performance can depend on a few factors, including the hosting provider, the hardware, what Craft fields you're using, etc. Craft tends to hit the database a lot so if your connection to MySQL isn't good—say on a mediocre shared hosting provider—that's going ...


6

A Categories field can be related to several categories. So you'll either need to limit your Category field to a single Category relationship or you'll need to make some assumption in how you build your URL as to which category will appear in the URL. The simplest assumption to make will be that you will always return the first category for your URL. Entry ...


6

Both titles can not appear in your condition(on the homepage). Always only one true statement is executed. To your problem: there is one global variable that solves your problem. {% if craft.request.getUrl() == siteUrl %} <h2>Homepage Title</h2> {% else %} <h2>Other Title</h2> {% endif %} There is also the link How Craft ...


5

The siteUrl config setting is not meant to be added under environmentVariables. 'test.dev' => array( 'siteUrl' => 'http://test.dev/', 'environmentVariables' => array( // ... ), // ... )


5

You're probably looking for something like: craft()->request->getHostInfo().craft()->request->getRequestUri(); Which will return the host name with the schema it's using (http:// or https://) as well as any URI after the host including any querystring parameters.


5

Multi-environment configs require you to create a '*' config array, even if it’s empty because there aren’t any config settings that you need to set globally. Simply having that '*' array is how Craft is able to determine that this is a multi-environment config, as opposed to '.dev' and '.org' just being normal config settings. (See the warning on http://...


5

Edit: Quick answer (as per RitterKnight's comment)... just add RewriteBase / to the top of your .htaccess file in the root of your public/public_html directory. I am on the same type of shared GoDaddy server, and continued to experience the same issue regardless of wether 'omitScriptNameInUrls' was set to true. I would get an "Internal Server Error" on ...


5

Try setting it as the actual siteUrl config setting, rather than a siteUrl environment variable. See here for an explanation.


5

I've already answered this question but ran into another situation that I feel merits a separate answer instead of making my first answer more complicated. In some cases, we use Cloudflare Flexible SSL. Due to the way Cloudflare does SSL, this adds support for SSL but not via a certificate on the server or via the standard SSL port so the common $_SERVER['...


5

So it seems the way to do this is actually by leaving the slug blank. If you happen to look down on the section setup screen prior to naming your section you'll see it clearly: Leave blank if this is the homepage. However since that field is automatically filled in with details from the Name/Handle fields I never actually saw the text by the time I was down ...


5

You can output the primary site’s Base URL like this: {{ craft.app.sites.primarySite.baseUrl }} (craft.app.sites maps to craft\services\Sites.) If your Base URL begins with an alias, you will need to parse it: {{ alias(craft.app.sites.primarySite.baseUrl) }} Altertatively, if you need to link to a sub-page of the primary site (not just its Base URL), ...


4

This recently tripped me up. 'true' (with quotes) is not the same as true (without the quotes). Lose the quotes in the config file, clear Craft's caches, and it should stick. Also make sure your siteUrl is the same as what your web server is configured as. If you have a redirect in there, say www.example.com goes to example.com, and your siteUrl is ...


4

{{ siteUrl }} should do the trick for you.


4

You can define whatever aliases/environment variables you like. In this case, I'd probably define an environment variable in my .env file like this: BASE_WEB=http://example.com And then in config/general.php I'd add an alias: <?php /** * General Configuration * * All of your system's general configuration settings go in here. You can see a * list ...


3

I have lord knows how many sites on GoDaddy (too many). The key to it is RewriteBase. Just add it to the default .htaccess and you're all set.


3

The default '.htaccess' file that comes with craft should not 'block' or redirect any files that exist; it simply routes what would otherwise be 404 requests (i.e. documents that don't exist) to craft, so that craft can attempt to resolve the route. If your sitemap is a static file, then the correct location would be in your public folder. If you are ...


3

Hey Jeremy you can actually make siteUrl work using Multi-Enviroment Configs and your general.php file will end up looking something like this. return array( '*' => array( // ... ), 'example.dev' => array( // ... 'environmentVariables' => array( 'basePath' => '/users/brandon/Sites/example.dev/public/', 'baseUrl' =&...


3

Make sure that you change .dev, .com, etc. to reflect your actual environment URLs. They operate based on a partial string match, so as long as your URL contains one of those substrings, it'll pick up the first one it matches. For example: 'local.mywebsite' => array( 'environmentVariables' => array( 'userSessionDuration' => false, '...


3

What web server are you running? I ask because IIS will define the $_SERVER['https'] variable even if the site is being accessed via HTTP (it's value will be 'off') and Ben's answer is only checking if the $_SERVER['https'] variable is present. One solution is to add a further check that $_SERVER['https'] == 'on' Try updating this: // Ensure our urls have ...


3

Have you tried changing the slug of the page to "__home__" (without quotes)?


2

As of Craft 2.2, you should now be using the new siteUrl setting. See this reply for more details. Your variable siteUrl from environmentVariables should still work, though. What do you see if you add this to a test template? <pre> {{ dump(craft.config.get('environmentVariables')) }} </pre> Check out How is the Site URL determined? from the ...


2

{{ siteUrl }} is just a simple URL taken from your config file, this is helpful for when you want to use absolute linking to things like style sheets js files, images etc. because it's dynamic you can set it differently depending on the environment and not have to worry about links breaking or putting a localhost link into a live template (which would fail) ...


2

What field type is blog_featured_image? Just an image asset? Does it work with <img src="{{ asset.getUrl() }}" alt="{{asset.title}}" /> ?


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