We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Plugin: In Segments

Development and Programming

Brian Litzinger's avatar
Brian Litzinger
711 posts
16 years ago
Brian Litzinger's avatar Brian Litzinger

This is a simple plugin to see if any value is present in any segment by either an exact match, or a wildcard. Not sure if something like this exists. I needed this today so I whipped this together quickly.

Download at: http://brianlitzinger.com/ee/

If URL is mysite.com/giving-birth-here/your-team/nurses-staff/, then the following if statement will return true.

{if "{exp:in_segments value='staff'}"}
    {embed="global/_staff_list" category="4"}
{if:else}
    {embed="global/_staff_list" category="5"}
{/if}

Parameters

exact= (optional) set to’y’ to do an exact segment match. In the example above only ‘nurses-staff’ would return as true.

return_segment= (optional) set to ‘y’ to return the segment number in which the match was found. By default the plugin returns true/1 or false/0.

       
Nicolas Bottari's avatar
Nicolas Bottari
143 posts
16 years ago
Nicolas Bottari's avatar Nicolas Bottari

litzinger, thanks for the plugin.

Actually, I had a similar plugin, called “Any segment”, which I also quickly created and did not (forgot to) mention here. 😊 Download: http://nicolasbottari.com/index.php/expressionengine/any_segment/

I think the only difference is your return_segment parameter, and the nomenclature 😉 These types of segment plugins are great for multilingual sites with template groups named after languages, with one being the default group. (eg. www.mysite.com/jp = www.mysite.com)

Glad I wasn’t the only one needing this 😊

       
Jim Pannell's avatar
Jim Pannell
187 posts
16 years ago
Jim Pannell's avatar Jim Pannell

Hi Brian,

This looks great! I actually have a need for exactly this type of addon right now - thanks!

Jim

       
Todd D.'s avatar
Todd D.
460 posts
16 years ago
Todd D.'s avatar Todd D.

Thanks Brian for your work on this. Sorely needed it was.

I posted a question/request for similar functionality here.

I don’t suppose you might add the ability to choose which segment to look at in the future?

       
LucPestille's avatar
LucPestille
146 posts
16 years ago
LucPestille's avatar LucPestille

How exactly does the return_segment work in a template?

{exp:in_segments value="promo" return_segment="y"}

…returns nothing as far as I can see. Do I have to do something like;

{if "{exp:in_segments value="promo" return_segment="y"}"}{segment}{/if}

?

       
LucPestille's avatar
LucPestille
146 posts
16 years ago
LucPestille's avatar LucPestille

I can’t seem to get the plugin to return the right segment, it seems to be returning 1 less than it should - with a url like domain.com/xxx/xxx/promo-xxx in_segments returns 2, not 3 (which I’ll feed into the {segment_x} when I’m done).

{if "{exp:in_segments value='promo-'}"}

{exp:in_segments value="promo-" return_segment="y"}

{exp:weblog:entries weblog="promos" search:promo_code="{segment_3}" limit="1" dynamic="off" disable="pagination|categories|member_data|trackbacks"}
<div class="promo">
    <h3>{exp:xml_encode}{title}{/exp:xml_encode}</h3>
    {promo_info}
    <a href="http://{promo_link}" title="{title}" class="focus-button focus-button-alt">Read more</a>
</div>
{/exp:weblog:entries}

{if:else}

{exp:weblog:entries weblog="promos" orderby="random" limit="1" dynamic="off" disable="pagination|categories|member_data|trackbacks"}
<div class="promo">
    <h3>{exp:xml_encode}{title}{/exp:xml_encode}</h3>
    {promo_info}
    <a href="http://{promo_link}" title="{title}" class="focus-button focus-button-alt">Read more</a>
</div>
{/exp:weblog:entries}

{/if}

Anyone spot anything wrong?

       
Todd D.'s avatar
Todd D.
460 posts
16 years ago
Todd D.'s avatar Todd D.

I’ll take a stab at it…

I’m wondering if the - in ‘promo-’ is causing an issue?

OR

Do you get the same results if the third segment closes with a forward slash also?

This domain.com/xxx/xxx/promo-xxx/ instead of domain.com/xxx/xxx/promo-xxx

       
LucPestille's avatar
LucPestille
146 posts
16 years ago
LucPestille's avatar LucPestille

Thanks - I’ll take a look. For now, I’ve got round it by just searching all the segments with

search:promo_code="={segment_1}|{segment_2}|{segment_3}|{segment_4}"

once I know that “promo-” appears in the URL…

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.