This plugin allows you to split url segment into subsegments array and find any subsegment.
PARAMETERS
1) segment - (integer from 1 to 9). Required. Allows you to specify which url segment will be parsed. Numbering of segments is the same as in ExpressionEngine’s url segment variables.
2) separator - (any string which consists from characters legal for use in url segment). Required. Allows you to specify the string according to which url segment will be split into array of subsegments.
3) on_failure - (‘segment’ or any string which consists from characters legal for use
in ExpressionEngine’s tag parameter values). Optional. Allows you to specify what variables of {exp:subsegment} tag will output in case needed subsegment was not found.
EXAMPLE OF USAGE:
If segment_3 is
/project_5-article_7-section_6/
then you can use {subsegment_0}, {subsegment_1} etc. variable within
{exp:subsegment}{/exp:subsegment} tag pair
{exp:subsegment segment="3" separator="-"}
{subsegment_1}
{/exp:subsegment}
It will return “article_7”.
Variables {subsegment_0}-{subsegment_8}
within {exp:subsegment}{/exp:subsegment} tag pair can be used
as parameter of other tag. For such use
you must add parse=“inward” parameter to {exp:subsegment} tag.
For example, code as this will work
{exp:subsegment segment="3" separator="-" parse="inward"}
{exp:weblog:entries weblog="my_weblog" url_title="{subsegment_1}"}
Some code
{/exp:weblog:entries}
{/exp:subsegment}
If subsegment does not exist then the tag by default will return nothing.
In case ‘on_failure’ parameter was defined, then, if subsegment does not exist,
the tag will output what was specified as value of this parameter.
If ‘segment’ is the value of ‘on_failure’ parameter, then the tag will output
segment, if segment exists. If ‘on_failure’ parameter has some other string as
its value, then that string will be outputted.
Conditionals are supported. The value of “on_failure” parameter has no effect
on the values of variables {subsegment_0}-{subsegment_8} inside conditionals.
E.g. if the value of “on_failure” parameter is “AAA” and the third subsegment
does not exist, then the variable {subsegment_2} will output “AAA” outside conditionals
and empty string inside conditionals.
Changelog:
-1.5 // Ditched support for {subsegment} variable; added support for conditionals.
-1.4 // Added invalid_input parameter.
-1.3.1 // Fixed bug - string specified as a value of “on_failure” parameter not being displayed in case needed segment not found.
-1.3 // Index parameter made optional. New variables {subsegment_0}-{subsegment_8} introduced.
-1.2.1 // Fixed bug - on_failure parameter causes result to be displayed as output of entire {exp:subsegment} tag instead of as output of {subsegment} variable.
-1.2 // Added on_failure parameter.
-1.1 // Added optional use of either single {exp:subsegment} tag or variable {subsegment} within {exp:subsegment}{/exp:subsegment} tag pair.
-1.0 // First release
