Page 1 of 1
A Redirect UDT
Posted: Thu Aug 23, 2007 2:05 am
by calguy1000
Below you will find the code for a UDT to do redirecting. I had to ask bbonora for this tag as I hadn't kept it.
Anyways. Create a new UDT under Extensions >> Tags, and call it 'redirect'. Then paste this code in there.
How do I use it: add {redirect to='page_alias'} into one of your pages, or somewhere intelligently placed in your template (you should have an if statement around this, or you'll get some nasty redirection loops).
Code: Select all
if( isset( $params['to'] ) )
{
global $gCms;
$manager =& $gCms->GetHierarchyManager();
$node =& $manager->sureGetNodeByAlias($params['to']);
$content =& $node->GetContent();
if (isset($content))
{
if ($content->GetURL() != '')
{
redirect($content->GetURL());
}
}
}
Re: A Redirect UDT
Posted: Thu Aug 23, 2007 4:52 pm
by davidlanier
yes, thanks! it's going into my code library for sure now!
Re: A Redirect UDT
Posted: Fri Dec 07, 2007 4:28 pm
by calguy1000
Here's a slightly modified version with a bit more error handling
Code: Select all
if( isset( $params['to'] ) )
{
global $gCms;
$manager =& $gCms->GetHierarchyManager();
$node =& $manager->sureGetNodeByAlias($params['to']);
$content =& $node->GetContent();
if (isset($content) && is_object($content))
{
if ($content->GetURL() != '')
{
redirect($content->GetURL());
}
}
else return '<!-- redirect udt - page not found: '.$params['to'].' -->';
}
Re: A Redirect UDT
Posted: Sat Dec 08, 2007 12:47 pm
by Pierre M.
just
wikied it.
@all : feel free to improve the documentation, as you have write access to the wiki with your forum account.
Pierre M.
Re: A Redirect UDT
Posted: Mon Dec 17, 2007 12:41 am
by richbothe
Love this UDT!! Thanks much
Re: A Redirect UDT
Posted: Tue Nov 16, 2010 2:57 am
by ESBertrand
Is there a way to modify this for use with the FEU module, so the user can be redirected back to the original page they wanted once they login? The "redirect after login" setting isn't useful for us, at least with a static page alias, but can the page alias be saved somehow at the original point of redirection, and used again with the redirect after login setting, maybe?
Any help greatly appreciated.
Erik
Re: A Redirect UDT
Posted: Wed Aug 31, 2011 3:02 pm
by lpkatalog
How can I redirect on site with URL containing GET params?
For example if I want to redirect on this site:
path:
Code: Select all
index.php?mact=Gallery,m721d7,default,1&m721d7dir=SamplePictures&m721d7returnid=56&page=56
When I use {redirect to='
path'} it of course is not working, but when I use {redirect_url to='
path'} on every place between params which are joined with
& this character is replaced with
& and then is redirecting not working.
Has somebody any reason how to redirect on the page where I could use URL with params ? Because I spent so much time for rearching any solution.
Re: A Redirect UDT
Posted: Wed Aug 31, 2011 5:27 pm
by ESBertrand
My original request was resolved - details here:
http://forum.cmsmadesimple.org/viewtopic.php?t=49065
Hope it helps!
Erik
Re: A Redirect UDT
Posted: Fri Sep 02, 2011 1:23 pm
by lpkatalog
Thanks for really fast answer.
I tried more ways how to resolve this problem and finally I have choosed this solution. This comment could be also included in some topics about gallery. Maybe this will help to somebody:
I use the same example as in my last comment:
path:
Code: Select all
index.php?mact=Gallery,m721d7,default,1&m721d7dir=SamplePictures&m721d7returnid=56&page=56
The basic problem was that when somebody click on one of items from menu it was necessary to show
specific gallery (default gallery) in content (page nr:65). But when I used tag
it wasn't working. The gallery was showed, but it was really a mess on this side (styles, template). When I added more params to the tag gallery, the gallery-items in page-content are shown allright.
Code: Select all
{Gallery dir='SamplePictures' returnid='56' page='56'}
I hope it's not necessary to use the param
mact.
This script can help you redirect on page with specific gallery in content (m721d7 is probably ID of gallery).
Code: Select all
{if $smarty.get.m721d7dir}
{Gallery dir=$smarty.get.m721d7dir}
{else}
{Gallery dir='SamplePicture' returnid='56' page='56'}
{/if}
So when is isset get param m721d7dir (in case if you redirect via anchor from another side and the link in anchor has param m721d7dir too) and when doesn't exist param m721d7dir then the default gallery shows.
Re: A Redirect UDT
Posted: Sat Sep 03, 2011 11:46 am
by ESBertrand
Excellent - thanks for sharing!
-Erik