CMS Made Simple Forums
https://forum.cmsmadesimple.org/

A Redirect UDT
https://forum.cmsmadesimple.org/viewtopic.php?f=7&t=14440
Page 1 of 1

Author:  calguy1000 [ Thu Aug 23, 2007 2:05 am ]
Post subject:  A Redirect UDT

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:
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());
         }
       }
  }

Author:  davidlanier [ Thu Aug 23, 2007 4:52 pm ]
Post subject:  Re: A Redirect UDT

yes, thanks!  it's going into my code library for sure now!

Author:  calguy1000 [ Fri Dec 07, 2007 4:28 pm ]
Post subject:  Re: A Redirect UDT

Here's a slightly modified version with a bit more error handling

Code:
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'].' -->';
  }

Author:  Pierre M. [ Sat Dec 08, 2007 12:47 pm ]
Post subject:  Re: A Redirect UDT

just wikied it.

@all : feel free to improve the documentation, as you have write access to the wiki with your forum account.

Pierre M.

Author:  richbothe [ Mon Dec 17, 2007 12:41 am ]
Post subject:  Re: A Redirect UDT

Love this UDT!!  Thanks much  ;D

Author:  ESBertrand [ Tue Nov 16, 2010 2:57 am ]
Post subject:  Re: A Redirect UDT

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

Author:  lpkatalog [ Wed Aug 31, 2011 3:02 pm ]
Post subject:  Re: A Redirect UDT

How can I redirect on site with URL containing GET params?

For example if I want to redirect on this site:

path:
Code:
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 &amp; 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.

Author:  ESBertrand [ Wed Aug 31, 2011 5:27 pm ]
Post subject:  Re: A Redirect UDT

My original request was resolved - details here:

viewtopic.php?t=49065

Hope it helps!

Erik

Author:  lpkatalog [ Fri Sep 02, 2011 1:23 pm ]
Post subject:  Re: A Redirect UDT

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:
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:
{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:
{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:
{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.

Author:  ESBertrand [ Sat Sep 03, 2011 11:46 am ]
Post subject:  Re: A Redirect UDT

Excellent - thanks for sharing!

-Erik

Page 1 of 1 All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/