Questions tagged [segments]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
1 vote
2 answers
442 views

Request Segment URL

I'm trying to declare if a user is on a /uk or /us version of the site. domain.com/uk/ domain.com/us/ {% if (craft.app.request.segments == '/uk/') %} UK site {% endif %} This doesnt work. Can ...
HeyImArt's user avatar
  • 111
2 votes
2 answers
2k views

How to get second last url segment

I'm setting up a dynamic thank-you page for all forms added to the site. Client can add forms with freeform to any page and I have set the return url to this: {{ form.renderTag({ class: "w-full ...
CreateSean's user avatar
  • 1,973
1 vote
2 answers
79 views

Routing and Segments

I'm using the following code for now: Route (in the control panel) recipes/{slug} loads _recipes/restaurant In the template to define the restaurant and list its items {% set restaurant = ...
Mark H.'s user avatar
  • 391
1 vote
1 answer
159 views

Routing: ignoring a segment from the URL

I am trying to configure my routes so that the last segment of the URL is ignored and can be used as parameter in the twig file. for example, the following URL should ignore the city-segment /...
tuursw's user avatar
  • 25
1 vote
1 answer
146 views

Filter by slug from URL (advanced)

Channel: Restaurants Channel: Nutrition / contains entries field named restaurant. Required URL format: restaurant-name-nutrition since the URL structure is merged I can't use getSegement(x) ...
Mark H.'s user avatar
  • 391
1 vote
1 answer
896 views

Templates, Routes, and URL segments

In EE, if there was a template /foo/bar.html, one could access the contents of that template by going to either example.com/foo/bar or example.com/foo/bar/more/segments/here. The additional URL ...
Sandwich's user avatar
  • 636
1 vote
2 answers
549 views

How do I remove segment 1 in my URL AND get the parent URI?

I have a structured group of pages in a static channel that I would like to display without "static" in the URL and show the parent URI. This is my structure: patients-visitors ---- our-stories ------...
Vaughn D. Taylor's user avatar
2 votes
1 answer
838 views

Template logic to address a third URL segment

I'm using Craft 3, and I'm struggling to make sense of how to address the following. (I've not had need to venture into a third URL segment before.) I have a url of the form: stories/{slug} served ...
Jonathan Schofield's user avatar
1 vote
1 answer
217 views

Locale URL segment being duplicated, eg https://website.test/en/en/

Problem I have a problem on a local Valet setup: the locale URL segment is appearing twice in URLs. Eg from a page at URL of en/about/approach, {{ url('about/approach')}} outputs https://website....
James Greig's user avatar
1 vote
1 answer
92 views

Categories Structure for Landing Pages

I'm using a category group and routes to serve up entries on landing pages with a URL structure like this. www.domain.com/properties/retail/freestanding My code works, but I am wondering if there's ...
triplethreat23's user avatar
3 votes
3 answers
2k views

Trimming lastSegment from a URI trims that PLUS the last number of the previous segment

I am fairly new to twig and templating with Craft (and I have inherited this code, so that makes it even more fun). I have a calendar page that lets you filter the events in the calendar based on a ...
jkilp's user avatar
  • 153
7 votes
2 answers
14k views

How to get a URL segment

I can see that craft.request.firstSegment and craft.request.lastSegment works but craft.request.secondSegment does not. Is there a way (as in ExpressionEngine) to get the value of any URL segment?
Andrew's user avatar
  • 738
1 vote
1 answer
187 views

Is it possible to change one segment of the current url and keep the rest of it the same in a cleaner way?

How would you go about changing one segment of the current url? I have a select in the footer that you can click on a country name and then it redirects you to the homepage of that country version of ...
hcone5006's user avatar
1 vote
1 answer
355 views

How to write a segment that is not two other segments

How can I write: is segment 3, and is not itemA and is not itemB? both itemA and itemB are segment 3 as well. {% if craft.app.request.getSegment(3) and craft.request.getSegment(3) !== 'itemA' and ...
TRIM's user avatar
  • 314
1 vote
1 answer
774 views

Use url segment as querystring parameter [Craft 3]

I have mysite.com and I need to use a segment as if it were a querystring parameter for accomplishing this: mysite.com/us -> same template as: mysite.com mysite.com/pricing/bz -> same ...
Rosana Ruiz's user avatar
1 vote
1 answer
320 views

Custom routes using kebab {type} in URL segment

I have a section that has multiple entry types. I would like to use kebab-style url segments in the URL format. I can get the articles to serve kebab URIs using this for the section's Entry URL Format:...
Shanan Galligan's user avatar
1 vote
1 answer
95 views

AMForms Action URL

I'm setting up landing pages in Craft where someone can fill out a very basic form and get an eBook. My idea was to have the form /info/landing-page-title submit to /info/landing-page-title/thank-you,...
Todd's user avatar
  • 284
0 votes
1 answer
129 views

Exclude entry based on segment

I am trying to exclude the current entry in a "Recommended Reading" section which works at level 1 with the ID tag, but I also need it to do the same at level 2 (children). `{% for entry in craft....
Nutmeg's user avatar
  • 598
1 vote
1 answer
766 views

How can I get all child categories - of a child category based on url segment?

I am missing something very obvious I think. I am trying to get all child categories based on url segment. For example: "mysite.com/foo" I have a category Group called Sections Within Sections I ...
Damon's user avatar
  • 4,706
0 votes
1 answer
36 views

Filter out part of _layout on a specific template

I have a site consisting of 15 templates, all of which extend _layout.html. There is just one page (homepage) which needs to omit a chunk of the _layout.html. Is there something I can add to _layout ...
Martin's user avatar
  • 1,203
3 votes
1 answer
474 views

Override a wildcard dynamic route template

I have a dynamic route for individual user /profiles. I expected it would be possible to override this route for /profiles/all but apparently not. This can be achieved in the template I expect, with ...
Rob's user avatar
  • 865
2 votes
0 answers
459 views

Checking if a value matches an entry type handle

I am trying to check if a value provided by the user (url segment) matches an entry type, and if not redirect to 404. {% set section = craft.sections.getSectionByHandle('shop') %} {% set entryTypes = ...
Samuel E.'s user avatar
  • 239
2 votes
1 answer
621 views

check if a route segment matches a section entry type

So i added a route to a template that shows entries by entry types. the way the template does it is by taking the last segment of the url, and using it as an entry slug for this filter: craft.entries....
Samuel E.'s user avatar
  • 239
2 votes
2 answers
276 views

Setting a variable assets field, depending on the URL?

How can I set different assets fields depending on the URL? I tried: {% if craft.request.getSegment(1) == 'special' %} {% set assetfield = variantfield1 %} {% endif %} {% for asset in entry....
noregt's user avatar
  • 1,062
2 votes
1 answer
379 views

Segment to filter through categories slug

I've seen plenty examples of using the uri segment like below, but it ain't working for me, anyone had same sort of issue? {% set segment = craft.request.segment(2) %} {% set pageCats = craft....
Samsull's user avatar
  • 151
1 vote
1 answer
1k views

How to get an entry title and URI from a segment in order to create a breadcrumb navigation

Is it possible to get an entry title and URI from a segment? e.g. If segment 1 has a value of 'about', I'd want to output an entry title of 'About Us', and a URI of 'mysite.com/about', and so on for ...
Stephen's user avatar
  • 685
7 votes
1 answer
1k views

How to use url segments like with Freebie in EE

I'm trying to make the jump from EE to Craft but struggling in this area (and thinking I may be approaching this all wrong). In EE, I often use url segments (in combination with Freebie to ignore ...
Mike's user avatar
  • 699
3 votes
0 answers
634 views

Filter entries with segments and params based on categories and fields [closed]

I'm working on a webshop with an advanced filter / search with multiple categories, entry types and fields and sorting options. Schematic URL site.com/template/entry.type/category/?size=category OR ...
Johannes Lamers's user avatar