A Redirect UDT

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Locked
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

A Redirect UDT

Post 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());
         }
       }
  }
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
davidlanier
New Member
New Member
Posts: 5
Joined: Mon Aug 13, 2007 11:01 pm

Re: A Redirect UDT

Post by davidlanier »

yes, thanks!  it's going into my code library for sure now!
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: A Redirect UDT

Post 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'].' -->';
  }
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
Pierre M.

Re: A Redirect UDT

Post 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.
User avatar
richbothe
Forum Members
Forum Members
Posts: 95
Joined: Tue Aug 15, 2006 5:34 pm
Location: Minnesota, USA

Re: A Redirect UDT

Post by richbothe »

Love this UDT!!  Thanks much  ;D
ESBertrand
Forum Members
Forum Members
Posts: 21
Joined: Tue Feb 02, 2010 5:02 am

Re: A Redirect UDT

Post 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
lpkatalog
New Member
New Member
Posts: 2
Joined: Wed Aug 31, 2011 2:36 pm

Re: A Redirect UDT

Post 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.
ESBertrand
Forum Members
Forum Members
Posts: 21
Joined: Tue Feb 02, 2010 5:02 am

Re: A Redirect UDT

Post by ESBertrand »

My original request was resolved - details here:

http://forum.cmsmadesimple.org/viewtopic.php?t=49065

Hope it helps!

Erik
lpkatalog
New Member
New Member
Posts: 2
Joined: Wed Aug 31, 2011 2:36 pm

Re: A Redirect UDT

Post 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

Code: Select all

{Gallery dir='SamplePictures'}
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.
ESBertrand
Forum Members
Forum Members
Posts: 21
Joined: Tue Feb 02, 2010 5:02 am

Re: A Redirect UDT

Post by ESBertrand »

Excellent - thanks for sharing!

-Erik
Locked

Return to “Modules/Add-Ons”