Hot answers tagged

9 votes

Using pagination on a page with url with query string data

In most Craft projects I do I'll create a pagination include file so anything I need that requires pagination, I can just include that and I get the same pagination pattern anywhere within my site ...
Tim Knight's user avatar
  • 1,022
9 votes
Accepted

How to get second last url segment

You can use negative numbers as the parameter for segment which then counts from right to left. So {{ craft.app.request.segment(-1) }} will get the last segment. And... {{ craft.app.request.segment(-...
foamcow's user avatar
  • 2,019
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,622
7 votes
Accepted

Asset (image) public URL does not work

The issue is that your Asset Volume URL is @web/image but your Asset Volume path is @webroot/assets/art That means that Craft will look for the images on disk (to do transforms, etc.) in web/assets/...
andrew.welch's user avatar
  • 11.4k
6 votes
Accepted

If page conditions

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....
Dominik Krulak's user avatar
6 votes
Accepted

Entry URL Format

There are two ways you can set that up, depending on whether you want Brand entries to have a similar URI format (just without the 3rd segment), e.g. category/brand. Assuming you do, edit your Brands ...
Brandon Kelly'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

Force trailing slash on URLs

Craft has a config setting for this (for dynamic urls) You can set it in your config file like so: 'addTrailingSlashesToUrls' => true If someone links to the url via a non-trailing-slash pattern,...
Jbird's user avatar
  • 151
5 votes

redirect index.php in urls on Craft site to NEVER show index.php

As another option that I usually do in addition to .htaccess, is to also add this to the array in craft/config/general.php file, and it'll stop Craft from ever adding the index.php. '...
Taylor Daughtry's user avatar
5 votes

I am unable to correctly return the url of an uploaded asset

I found the answer in a similar post here: Image asset url is not being output My problem was with my Asset Source settings. Now that I think about it, it's obvious: I had no public URL declared for ...
Steven Thate's user avatar
5 votes
Accepted

The requested URL was not found on this server

Try going to yoursite.com/index.php/(pagename). If that works, check out this article on how to remove it: https://craftcms.com/support/remove-index.php
strandall's user avatar
  • 188
5 votes
Accepted

Use global values in the Entry URL Format field

Your CraftCMS global can be accessed using the code {{craft.globals.getSetByHandle('siteDefaults').artworksList.first.uri|default}}/{slug} I believe the issue is that the Entry URL field requires ...
Regan Lawton's user avatar
5 votes

Change posts url without losing SEO positioning

Migrating Redirects should not be thought of as a one-time event but a process that includes a step where you make sure Redirects are in place and working. A rough redirect strategy Take a snapshot ...
Ben Parizek's user avatar
  • 13.4k
5 votes
Accepted

Why is $DEFAULT_SITE_URL appearing in entries URL?

You probably have a misconfiguration in your environment variables - First go to the control panel and check what you have under Settings > Sites > [choose site] > Base URL. If it's set to an ...
James Smith's user avatar
  • 4,924
4 votes
Accepted

redirect index.php in urls on Craft site to NEVER show index.php

This came up in the Craft Slack not so long ago. You'd want something like this... # ------------------------------------------------------------ # Remove index.php # ---------------------------------...
Jamie Pittock's user avatar
4 votes

Nest Entries from Different Sections

The Team section’s landing page could just be a template living at about/team/index.html. From there if you want to output info about the team members, just fetch it manually: {% for teamMember in ...
Brandon Kelly's user avatar
4 votes
Accepted

Including two category slugs in entries’ URLs

Set your section’s Entry URL Format to this: {mySection.first.slug}/{myCategory.first.slug}/{slug} mySection.first and myCategory.first will give you the first-selected category within those ...
Brandon Kelly's user avatar
4 votes

Strange 'index.php' Issue

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 ...
RitterKnight's user avatar
  • 6,572
4 votes
Accepted

provide a 'back' or 'cancel' or 'close' button to return to whatever page that particular template was accessed from

You could use the Cookies plugin to store the last visited URL before the user hits one of the "step" templates, i.e. by putting something like the following in every template where the links to the "...
Mats Mikkel Rummelhoff's user avatar
4 votes
Accepted

Setting channel url format to include value of entries fieldtype URL

It needs to be: {destination.first().slug} Or if this is for Craft 3: {destination.one().slug}
Brandon Kelly's user avatar
3 votes
Accepted

Bilingual site page URL issues

Well... the answer was quite simple. 'siteUrl' => array( 'en_ca' => 'http://localhost/mysite', 'fr_ca' => 'http://localhost/mysite/fr', ), The _ca part was what was missing. Now my ...
Eric Chantigny's user avatar
3 votes
Accepted

Override a wildcard dynamic route template

Sort order matters, move the more specific route up and you should be good. Alternativly set it up in routes.php using some regular expressions.
carlcs's user avatar
  • 36.2k
3 votes

Add home page to a structure?

From an IA and content-modelling perspective, putting all your site's "pages" in a Structure is fraught with problems, and, in my opinion, does a terrible disservice to the future-friendly approach ...
James Smith's user avatar
  • 4,924
3 votes

Entry Types Custom Slug

You can use twig filters in url structures as mentioned by RhealPoirier in a comment above, no need for a plugin: my-section/{type.handle|replace('/(^|[a-z])([A-Z])/', '\\1-\\2')|lower}/{slug} or ...
plankguy's user avatar
3 votes
Accepted

Does it make sense to use Craft with relative links?

I would question the need to have relative URLs to begin with. As Brad mentions, Craft neatly solves the multi-environment problem for you. If you come from an environment like WordPress where it ...
RitterKnight's user avatar
  • 6,572
3 votes
Accepted

Adding .html to end of page url?

You can change your entry's URL format right inside Craft. It's under Settings -> Sections then choose the section you want. Under URL Format, just add .html after the {slug}. In this example, I'...
RitterKnight's user avatar
  • 6,572
3 votes

Multiple URL Formats per element type (Entries, Categories)

So semantically, I don’t love the URL format you’re coming up with. I’d like to see something like /gear/{category}/{entry} This gives you a few benefits it’s semantically readable… it gives you ...
andrew.welch's user avatar
  • 11.4k
3 votes
Accepted

URL drops :8888 from localhost

I would try and put the port in your siteUrl config param: 'siteUrl' => 'http://localhost:8888', Alternatively you might be able to use this though haven't tested it (I believe the php server ...
joep's user avatar
  • 610
3 votes
Accepted

What's the best way to build URLs for dynamic content collections?

You need that custom route. With the dynamic URI setting the "entry route" is generated dynamically on entry save, but it stores a single, fixed route only. But you don't have to miss out on Live ...
carlcs's user avatar
  • 36.2k
3 votes
Accepted

404s on custom sections and entries

You'll need to create a template, and add the path to that template to the Entry Template field in your "Services" section's settings. For instance, if you create a template called /craft/templates/...
Mats Mikkel Rummelhoff's user avatar

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