If it is impossible by usual means to check if condition for redirection was met or not you can
check it by wrapping the code expressing condition by {exp:redirect_to}{/exp:redirect_to} tags.
Redirection will be performed if the code wrapped by {exp:redirect_to}{/exp:redirect_to} tags will produce
no output.
{exp:redirect_to location="my_template_group/my_template" method="script"} {exp:query sql="SELECT title FROM exp_weblog_titles WHERE weblog_id = '5' AND url_title ='My title'"} {title} {/exp:query} {/exp:redirect_to}
If you want that redirection would be performed on condition that certain output were produced, you should
enter expected string as a value of “tagdata” parameter. Then the redirection will be performed if
the string entered as “tagdata” parameter value and output of the code
wrapped by {exp:redirect_to}{/exp:redirect_to} tags are identical. (Tabs, spaces and new line characters
will be stripped.) In example below redirect will occur if {exp:query tag} will produce string “1”.
{exp:redirect_to location="my_template_group/my_template" tagdata="1" method="script"} {exp:query sql="SELECT title FROM exp_weblog_titles WHERE weblog_id = '5' AND url_title ='My title'"} {total_results} {/exp:query} {/exp:redirect_to}
Basically if you place this into a template then you will be re-directed to the URL specified in the location parameter.
I must admit I hadn’t even checked to see if those would work or not but I just tried with your second example with the {segment_3} option and that seems to work fine. The top one I haven’t tried yet but not too sure where you are getting those variables from? For instance the {weblog} variable. Is that a Global variable that you have created?
The documentation for that function in ExpressionEngine says the following :
redirect(location [string])
Redirect to location. Class: Functions (FNS) Description: Redirects current browser page to location. Does redirect either by location or meta refresh, depending on the redirect method preference.
Hope that answers the second question as to tell the truth I wasn’t too sure myself
{if segment_3 == "{exp:member:custom_profile_data}{pebble_group}{/exp:member:custom_profile_data}" } You are on the right page. {if:else} You are on the wrong page my friend. Let me redirect you. {exp:redirect_to location="http://www.mysite.com/group/"} {/if}
If I leave out your redirect code the text outputs properly. With your code, it redirects regardless of weather the conditional is true or not.
That seems to work fine. Not too sure what is up with the ifelse structure though. Perhaps one of the admins could pop in here and let us know?
{if:else} is an advanced conditional. That means EE will parse everything inside of the {if} {/if} statement and just HIDE what doesn’t need to show up. So your plugin WILL parse (thus redirect) and EE will just hide the results. But since your plugin doesn’t give back results (it redirects) it will always redirect inside an advanced conditional
Hmm yes it does seem to be a problem with these conditionals. I will have to look into that when I get the chance. For now though could you possibly embed a template that does what you need?
I just gave this a try and it will definitely do what you need. Also just noticed that in your code you had logged in instead of logged_in. Not sure if that will help with this though although that code is incorrect.
I’m delighted to say that it wasn’t because I’d missed that underscore because right now I would be feeling unbelievably foolish.
And I’m equally delighted to confirm that the include method works fine too so that’s perfect for this particular need. Thanks lots and indeed ‘doozazzle’.
I’m delighted to say that it wasn’t because I’d missed that underscore because right now I would be feeling unbelievably foolish.
Andy Harris - 27 February 2008 10:14 AM
And I’m equally delighted to confirm that the include method works fine too so that’s perfect for this particular need. Thanks lots and indeed ‘doozazzle’.
No problem at all. Well done on the doozazzle. Sorry if I bored you with what was above it? Let’s not give the game away to everyone in the forums though!!
Hi Mark, didn’t know where to post my question about you wiki article (Redirect User Upon Logging In) as I wasn’t able to post a question on the wiki. I’m having a problem where FireFox isn’t redirecting to the url specified in the cookie. Was wondering if this is a know problem?
Wiki article: http://expressionengine.com/wiki/Redirect_User_Upon_Logging_In/