EllisLab text mark
Advanced Search
     
NEW - Traverse Segments Plugin…
Posted: 07 June 2008 07:35 PM   [ Ignore ]
Avatar
Joined: 2006-04-15
12649 posts

Hiya,

Another very very quick plugin made in about a minute so hopefully it works as advertised wink

This one is for returning the value of a certain URI segment working from the end of the URI backwards.

Usage :

{exp:traverse_segments position="0"}
{segment}
{if 
'{segment}' == "test"}
YAY
{
/if}
{
/exp:traverse_segments} 

Parameters :

position=“0”
This will retrieve the last segment

position=“1”
This would retrieve the last but one segment and so on and so forth!

Variables :
{segment}
Returns the value of the requested segment

Possibilities :

{if '{segment}' == "tests"}
<p>Segment was the same!!</p>
{/if} 

Disclaimer - Not too sure if the if conditional above is entirely the correct way to do things. I mean with the ‘{segment}’ part. I think there is probably a better way to do this but it should work as is. Spitting out the {segment} variable should work without any problems though.


If the segment you had requested was in this case equal to tests then the message would be returned


Hope this is of some use to people. Hopefully it will work correctly on all systems too because as I said this was created very very quickly wink

Best wishes,

Mark

 Signature 

Shopping Cart Plugin | Full List Of Add-Ons | About Me
——————————————————————————————
2.x Bug Tracker | Upgrade Errors

 
Posted: 07 June 2008 08:17 PM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2005-07-16
501 posts

This was working before the name change, but now it’s spitting the {segment} out at the very top of my template instead of where I specify it in the template code.

 Signature 

Travis Schmeisser // rockthenroll


Structure is a powerful add-on that lets you create pages, generate navigation, manage content through a simple interface and build robust sites faster than ever.
http://buildwithstructure.com

 
Posted: 07 June 2008 08:20 PM   [ Ignore ]   [ # 2 ]   [ Rating: 0 ]
Avatar
Joined: 2006-04-15
12649 posts

Hi Travis,

Sorry about the name change. Check that you changed the code for the usage on this plugin to this :

{exp:traverse_segments position="0"}
{segment}
{if 
'{segment}' == "test"}
YAY
{
/if}
{
/exp:traverse_segments} 

That should hopefully work for you?

Best wishes,

Mark

 Signature 

Shopping Cart Plugin | Full List Of Add-Ons | About Me
——————————————————————————————
2.x Bug Tracker | Upgrade Errors

 
Posted: 07 June 2008 08:20 PM   [ Ignore ]   [ # 3 ]   [ Rating: 0 ]
Avatar
Joined: 2005-07-16
501 posts

Also, if I use multiple instances I get an error:

Notice: Undefined offset: -1 in F:\inetpub\vhosts\domain-here.com\httpdocs\ee\plugins\pi.traverse_segments.php on line 45

 Signature 

Travis Schmeisser // rockthenroll


Structure is a powerful add-on that lets you create pages, generate navigation, manage content through a simple interface and build robust sites faster than ever.
http://buildwithstructure.com

 
Posted: 07 June 2008 08:20 PM   [ Ignore ]   [ # 4 ]   [ Rating: 0 ]
Avatar
Joined: 2005-07-16
501 posts

I am using the new code including the new name…

 Signature 

Travis Schmeisser // rockthenroll


Structure is a powerful add-on that lets you create pages, generate navigation, manage content through a simple interface and build robust sites faster than ever.
http://buildwithstructure.com

 
Posted: 07 June 2008 08:21 PM   [ Ignore ]   [ # 5 ]   [ Rating: 0 ]
Avatar
Joined: 2006-04-15
12649 posts

Also ensure you download the plugin again from the top of this thread and install it and delete the old one?

Best wishes,

Mark

 Signature 

Shopping Cart Plugin | Full List Of Add-Ons | About Me
——————————————————————————————
2.x Bug Tracker | Upgrade Errors

 
Posted: 07 June 2008 08:23 PM   [ Ignore ]   [ # 6 ]   [ Rating: 0 ]
Avatar
Joined: 2006-04-15
12649 posts
rockthenroll - 08 June 2008 12:20 AM

Also, if I use multiple instances I get an error:

Notice: Undefined offset: -1 in F:\inetpub\vhosts\domain-here.com\httpdocs\ee\plugins\pi.traverse_segments.php on line 45

Just tried here with multiple instances on the new plugin and all seems to be okay. Hopefully it is now working for you with the new plugin and code?

Best wishes,

Mark

 Signature 

Shopping Cart Plugin | Full List Of Add-Ons | About Me
——————————————————————————————
2.x Bug Tracker | Upgrade Errors

 
Posted: 07 June 2008 08:30 PM   [ Ignore ]   [ # 7 ]   [ Rating: 0 ]
Avatar
Joined: 2005-07-16
501 posts

Ok, new copy of the plugin fixed functionality.

Still getting this error (only when logged in though):

Notice: Undefined offset: -1 in F:\inetpub\vhosts\phdmc.controlpanel2.donet.com\httpdocs\ee\plugins\pi.traverse_segments.php on line 46

Notice: Undefined offset: -2 in F:\inetpub\vhosts\phdmc.controlpanel2.donet.com\httpdocs\ee\plugins\pi.traverse_segments.php on line 46

Could it be something weird with the hosting setup? I haven’t been able to get a few things working on it, like removing index.php and “force query strings” is on.

 Signature 

Travis Schmeisser // rockthenroll


Structure is a powerful add-on that lets you create pages, generate navigation, manage content through a simple interface and build robust sites faster than ever.
http://buildwithstructure.com

 
Posted: 07 June 2008 08:37 PM   [ Ignore ]   [ # 8 ]   [ Rating: 0 ]
Avatar
Joined: 2006-04-15
12649 posts
rockthenroll - 08 June 2008 12:30 AM

Could it be something weird with the hosting setup? I haven’t been able to get a few things working on it, like removing index.php and “force query strings” is on.

Possibly but as I said I did throw this together very very quickly so it may be something I did. Hopefully one of the moderators will see this thread and download and take a look at the plugin to see if I have done anything wrong.

Sorry that it is causing errors. None here on 4 sites I have tested it on. 2 localhost and 2 real world. Hopefully one of the moderators or one of the other programmers will pick up on anything I have done wrong though.

Best wishes,

Mark

 Signature 

Shopping Cart Plugin | Full List Of Add-Ons | About Me
——————————————————————————————
2.x Bug Tracker | Upgrade Errors

 
Posted: 07 June 2008 08:47 PM   [ Ignore ]   [ # 9 ]   [ Rating: 0 ]
Avatar
Joined: 2005-07-16
501 posts

No worries. It does work, just getting the errors. Thanks again!

 Signature 

Travis Schmeisser // rockthenroll


Structure is a powerful add-on that lets you create pages, generate navigation, manage content through a simple interface and build robust sites faster than ever.
http://buildwithstructure.com

 
Posted: 07 June 2008 08:52 PM   [ Ignore ]   [ # 10 ]   [ Rating: 0 ]
Avatar
Joined: 2006-04-15
12649 posts

No problems, well apart from the problems that is!

Hopefully someone will see if I have done something that might be throwing those errors though if indeed it isn’t anything to do with your server problems.

Hope it is still useful though.

Best wishes,

Mark

 Signature 

Shopping Cart Plugin | Full List Of Add-Ons | About Me
——————————————————————————————
2.x Bug Tracker | Upgrade Errors

 
Posted: 07 April 2009 06:42 PM   [ Ignore ]   [ # 11 ]   [ Rating: 0 ]
Joined: 2008-01-06
86 posts

Mark,
  Love this plug-in, but of course I’m writing because I have a problem.  I’m trying to get the category id of a category that matches the same name as a segment in my url.

{exp:traverse_segments position="1"}
    {exp
:category_id category_group="9" category_url_title="segment"}
        {embed
=site/video-gallery video-cat="{category_id}"}
    {
/exp:category_id}
{
/exp:traverse_segments} 

The problem is that I can’t get the segment value to work in the category_id tag.  I’ve tried everything I can think of…  {segment}, “{segment}”, “‘{segment}’”, segment
Nothing seems to work.  Not a huge deal, I can work around it, but it’d be slick if I could make this happen. 

Any thoughts?

-kev