URL manipulation—help me find the right plugin
Posted: 08 September 2008 02:21 AM   [ Ignore ]  
Lab Assistant
Avatar
RankRank
Total Posts:  141
Joined  10-13-2002

I’m wanting to find the current page’s URL, then take segment 2, the template group, and replace it with some other text—the name of another template group. Can anybody suggest a plugin that does this, or facilitates this?

Profile
 
 
Posted: 08 September 2008 04:32 AM   [ Ignore ]   [ # 1 ]  
Research Scientist
Avatar
RankRankRankRankRankRank
Total Posts:  6610
Joined  04-15-2006

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

 Signature 

Full List Of Plugins Here!! (16)
 
Retrieve Statuses
Maximum Posts Reached
Neat Link
Redirect
Fetch URI

Profile
 
 
Posted: 08 September 2008 08:22 AM   [ Ignore ]   [ # 2 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  141
Joined  10-13-2002

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.

Profile
 
 
Posted: 08 September 2008 12:23 PM   [ Ignore ]   [ # 3 ]  
Research Scientist
Avatar
RankRankRankRankRankRank
Total Posts:  6610
Joined  04-15-2006

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

 Signature 

Full List Of Plugins Here!! (16)
 
Retrieve Statuses
Maximum Posts Reached
Neat Link
Redirect
Fetch URI

Profile
 
 
Posted: 08 September 2008 02:59 PM   [ Ignore ]   [ # 4 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  326
Joined  03-18-2007

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.

Profile
 
 
Posted: 08 September 2008 03:12 PM   [ Ignore ]   [ # 5 ]  
Research Scientist
Avatar
RankRankRankRankRankRank
Total Posts:  6610
Joined  04-15-2006

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

 Signature 

Full List Of Plugins Here!! (16)
 
Retrieve Statuses
Maximum Posts Reached
Neat Link
Redirect
Fetch URI

Profile
 
 
Posted: 08 September 2008 05:04 PM   [ Ignore ]   [ # 6 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1097
Joined  03-22-2006

If it is always the first segment (1) that you want to replace this should suffice.

<?php
global $IN, $FNS;
$new = $FNS->create_url('my-new-first-segment/'.implode('/', array_slice(explode('/', $IN->URI), 1)));
?>

 Signature 

(a.k.a the_butcher)

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 1149, on July 16, 2007 09:33 AM
Total Registered Members: 65086 Total Logged-in Users: 34
Total Topics: 82224 Total Anonymous Users: 24
Total Replies: 441923 Total Guests: 205
Total Posts: 524147    
Members ( View Memberlist )