Hi Brendon,
When you say take segment 2 and replace it exactly what do you need to do with it and how do you mean replace?
You can get hold of the different segments using the {segment_1} / {segment_2} etc variables that are available all the time in ExpressionEngine without the need for a plugin but it all depends on what you mean by replace the text?
Best wishes,
Mark
Let’s say the current URL is /foo/segment_3/segment_4/ – what I’m looking for is a way to grab that URL and then create a new URL replacing “foo” with “bar”, as in /bar/segment_3/segment_4/ – without knowing in advance how many segments actually exist. The only one I want to replace is the (segment_2}.
This is in relation to a multi-language setup, where the template groups stand for the active language.
Okay,
Let’s say you have this URL :
http://www.example.com/site/en/template-group/template/my_url_title
If you want to fetch the current URL and change the second segment then the easiest way to do this would be :
http://www.example.com/{segment_1}/fr/{segment_3}/{segment_4}/{segment_5}
That should hopefully do it for you although I’m still not entirely sure why you need to do this and where exactly or more importantly at what stage. Do you have a link to the site you are doing this on just so that I can get more of an idea of which stage you need to do this at?
Best wishes,
Mark
Make sure you don’t switch segment numbers here Brandon. In your example /foo/ is segment 1 (segment 1 is the template group).
Also, there are some ways using PHP and the various EE classes to grab the URLs and segment values in addition to Mark’s method. Are you comfortable with PHP? Take a look at the “Fetch Segments of the URL” area of this page: http://expressionengine.com/docs/development/usage/input.html.
Yep as slapshotw has mentioned there are a lot more ways of getting at the current URI. I created a plugin some time back that does just that. The link is also in my signature too.
Probably wouldn’t work for what you want to do here but you can take a look at how it works and modify at will if you like.
Best wishes,
Mark
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.