Questions tagged [segments]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
1
vote
2answers
45 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 ...
2
votes
2answers
141 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 ...
1
vote
2answers
55 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 = ...
1
vote
1answer
43 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 /...
6
votes
2answers
7k 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?
1
vote
1answer
45 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) ...
1
vote
1answer
516 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 ...
1
vote
2answers
309 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 ------...
2
votes
1answer
580 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 ...
1
vote
1answer
145 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....
1
vote
1answer
71 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 ...
3
votes
2answers
961 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 ...
1
vote
1answer
108 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 ...
1
vote
1answer
683 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 ...
1
vote
1answer
261 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 ...
1
vote
1answer
265 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:...
7
votes
1answer
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 ...
1
vote
1answer
89 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,...
0
votes
1answer
103 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....
1
vote
1answer
648 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 ...
0
votes
1answer
29 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 ...
3
votes
1answer
382 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 ...
2
votes
0answers
380 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 = ...
2
votes
1answer
536 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....
2
votes
2answers
263 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....
2
votes
1answer
313 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....
1
vote
1answer
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 ...
3
votes
0answers
624 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 ...