This looks like a nice alternative to MD Detect Page Type. The logic might be a little cleaner using Switchee. Think I’ll give it a try on my current project.
Can {member_group} be used as the variable to test against? I’ve got the following in an embedded template but doesn’t seem to work. Is it a parsing order problem / that it’s within an embed?:
{exp:switchee variable="{member_group}" parse="inward"}
{case value="1|6"}
admin content
{/case}
{case default="Yes"}
non-admin content
{/case}
{/exp:switchee}You’re right, member_group must be parsed later by EE.
If you enable php at input stage for your template you could do it like this:
{exp:switchee variable="<?php global $SESS; print(@$SESS->userdata['group_id']); ?>" parse="inward"}
{case value="1|6"}
admin content
{/case}
{case default="Yes"}
non-admin content
{/case}
{/exp:switchee}The alternative would be to write a small plugin and wrap switchee with it.
$plugin_info = array(
'pi_name' => 'My Plugin',
'pi_version' => '',
'pi_author' => '',
'pi_author_url' => '',
'pi_description' => 'Does stuff',
'pi_usage' => My_plugin::usage()
);
class My_plugin {
var $return_data;
function My_plugin()
{
global $SESS, $TMPL;
$this->return_data = $TMPL->swap_var_single('member_group', @$SESS->userdata['group_id'], $TMPL->tagdata);
}
function usage()
{
}
}and then:
{exp:my_plugin parse="inward"}
{exp:switchee variable="{member_group}" parse="inward"}
...
{/exp:switchee}
{/exp:my_plugin}Mark,
I’m using your plugin and finding that my “no_results” weblog checks are not working properly. Is this because of the parsing order? Can you think of a way around this?
{exp:switchee variable="{segment_3}" parse="inward"}
{case value="#^P(\\d+)$#|''"}
{exp:weblog:entries weblog="profile_blogs" sort="asc" limit="2" }
<h4><a href="/blogs/{segment_2}/{url_title}">{title}</a></h4>
{if no_results}
<div class="no_results">
No results
</div>
{/if}
{/exp:weblog:entries}
{/case}
{/exp:switchee}In the above code the “no results” conditional does not work if the parse=”inward” parameter is set on the switchee plugin
Hi Mark,
I did some hacking with Switchee plugin:
1) I added “excise” parameter.
“excise” parameter accepts two values - “max” (default) and “min”. It allows you to specify if tagdata which surrounds matched case should be outputted (min) or not (max). E.g. in case {variable_to_test} has as its value the value1 the code
{exp:switchee variable = "{variable_to_test}" excise="max" parse="inward"}
blah blah blah
{case value="value1"}
AAAAAAAAA
{/case}
blah blah blah
{case value="value2"}
BBBBBBBB
{/case}
blah blah blah
{/exp:switchee}will output
AAAAAAAAA
But the code
{exp:switchee variable = "{variable_to_test}" excise="min" parse="inward"}
blah blah blah
{case value="value1"}
AAAAAAAAA
{/case}
blah blah blah
{case value="value2"}
BBBBBBBB
{/case}
blah blah blah
{/exp:switchee}in case {variable_to_test} has as its value the value1 will output
blah blah blah AAAAAAAAA blah blah blah blah blah blah
2) It is not possible to nest plugin tags. In order to circumvent tthis limitation I created the clone of Switchee plugin - Switchee2. Using Switchee and Switchee2 it is possible to write the code as this:
{exp:switchee variable = "{variable_to_test}" parse="inward"}
blah blah blah
{case value="value1"}
blah blah blah
{exp:switchee2 variable = "{variable_to_test}" parse="inward"}
{case2 value="value3"}
AAAAAAAAA
{/case2}
{case2 value="value4"}
CCCCCCCCCCCC
{/case2}
{/exp:switchee2}
blah blah blah
{/case}
blah blah blah
{case value="value2"}
BBBBBBBB
{/case}
blah blah blah
{/exp:switchee}If you like my additions, feel free to incorporate them into official version.
Hmm I seem to have been unsubscribed from this thread for some reason. Sorry all for not replying sooner.
@Joe Wolin If you put {exp:weblog:entries} tag in an embedded template then your no_results tag will work as expected.
@Royal Glenora Club Just as soon as I do a job with EE2 I’ll port it. Should be dead simple.
@Laisvunas Those are very interesting additions. The ‘excise’ parameter is very neat indeed, I think I’ll add that to the ‘official’ version 😊
Nesting - it seems somewhat unelegant to have to clone the plugin to get nesting, so I’m not sure about that one. It does suggest another solution - parsing the tag data and inserting aliases for nested tags, then parsing the aliases recursively. I’m going to have a think about it a bit.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.