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}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.
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 😊
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?
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?
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.