Welcome, Guest. Please login or register.
Did you miss your activation email?
16 May 2008, 08:32

Login with username, password and session length
Home Chat Help Search Calendar Login Register
Pages: [1]
Print
Author Topic: A Redirect UDT  (Read 1382 times)
0 Members and 1 Guest are viewing this topic.
calguy1000
Posts that don't follow the rules (don't ask what the rules are, read them) will be ignored, moved or deleted
Dev Team Member
Power Poster
*****

Karma: 141
Offline Offline

Posts: 3484

Location: Calgary, Canada



WWW
« on: 22 Aug 2007, 21:05 »

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

----
CMS Made Simple is Simple - For experienced developers.   You don't need to know php to use CMS but you should have some experience with website design, website development, and supporting dynamic applications in a hosted environment.   The words CSS, XHTML, and permissions should not be new to you.
davidlanier
Forum Member
*

Karma: 0
Offline Offline

Posts: 5


« Reply #1 on: 23 Aug 2007, 11:52 »

yes, thanks!  it's going into my code library for sure now!
Logged
calguy1000
Posts that don't follow the rules (don't ask what the rules are, read them) will be ignored, moved or deleted
Dev Team Member
Power Poster
*****

Karma: 141
Offline Offline

Posts: 3484

Location: Calgary, Canada



WWW
« Reply #2 on: 07 Dec 2007, 10:28 »

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

----
CMS Made Simple is Simple - For experienced developers.   You don't need to know php to use CMS but you should have some experience with website design, website development, and supporting dynamic applications in a hosted environment.   The words CSS, XHTML, and permissions should not be new to you.
Pierre M.
Support Team member
Support Guru
Power Poster
****

Karma: 28
Offline Offline

Posts: 2404

Location: Paris

Please keep it simple


« Reply #3 on: 08 Dec 2007, 06:47 »

just wikied it.

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

Pierre M.
Logged

-- Pierre, support team member. comodérateur du forum francophone.
Please read "how to submit installation/debug help requests" before posting. Don't send private messages to ask for support.
Want to contribute to CMSms ? Improve the wiki with your forum account.
richbothe
Forum Member
*

Karma: 0
Offline Offline

Posts: 28


« Reply #4 on: 16 Dec 2007, 18:41 »

Love this UDT!!  Thanks much   Grin
Logged
Pages: [1]
Print
Jump to: