Page 1 of 1

need to add outside URL link within array

Posted: Tue Apr 13, 2010 10:50 am
by kevinwinters
I am working on a site that uses smarty templates and the owner has asked that part of the left navigation menu contain a link to a page that is not on their site, now the following code is the start of their naivation and contains links that are inside their site (like "inventory.php")

I tried to add the "Test Blog" link into the array but it comes out in the menu like "http://home site/http://test.hubspot.com...."

Is there a way I can display a link that is not inside their site within this array?

Code: Select all

<?php
$aMenu = array(
	'Home'=>'index.php',
	'View Inventory'=>'inventory.php',
      'Test Blog'=>'http://test.hubspot.com/CMS/UI/Modules/BizBlogger/4903fb476cf3'

	);
foreach($aMenu as $page=>$url):
	echo '<div><a href="'.$GLOBALS['cfg']['paths']['rel'].$url.'"';
	if($url==basename($_SERVER['PHP_SELF']))
		echo ' class="menuon"';
	echo '>'.$page.'</a>';
	echo '</div>';
endforeach;
...

Thanks for any direction on this

Re: need to add outside URL link within array

Posted: Tue Apr 13, 2010 11:21 am
by roders
The problem here is the that everylink that you will put will come out as http://home site/http://test.hubspot.com. My suggestion is append your link name with an identifier
for example try this.

Code: Select all

$aMenu = array(
   'LNKHome'=>'index.php',
   'LNKView Inventory'=>'inventory.php',
      'URLTest Blog'=>'http://test.hubspot.com/CMS/UI/Modules/BizBlogger/4903fb476cf3'

   );
foreach($aMenu as $page=>$url):
    switch (substr($page,0,3))
	{
		case("LNK"):
			$link=$GLOBALS['cfg']['paths']['rel'];
		break;
		case("URL"):
			$link=$url;
		break;
		default:
			$link=$GLOBALS['cfg']['paths']['rel'];
		break;
	}
	
   echo '<div><a href="'.$link.'"';
   if($url==basename($_SERVER['PHP_SELF']))
      echo ' class="menuon"';
   echo '>'.$page.'</a>';
   echo '</div>';
endforeach;
See how i've append LNK (Internal link) URL (Url link). try and let me know how it worked.

Re: need to add outside URL link within array

Posted: Tue Apr 13, 2010 12:14 pm
by kevinwinters
Seems very close to what I was looking for, thank you, only things were
(1) names displayed had the "LNK" and "URL" prefixes on them in the menu
(2) the inventory link and the home link linked simply to the main page ie inventory did not point to http://mainpage/inventory.php, just to http://mainpage

The url page pointed exactly how I needed it

Re: need to add outside URL link within array

Posted: Wed Apr 14, 2010 3:21 am
by roders
Ok done this should definitely work now.

Code: Select all

$aMenu = array(
   'LNKHome'=>'index.php',
   'LNKView Inventory'=>'inventory.php',
      'URLTest Blog'=>'http://test.hubspot.com/CMS/UI/Modules/BizBlogger/4903fb476cf3'

   );
foreach($aMenu as $page=>$url):
    switch (substr($page,0,3))
        {
                case("LNK"):
                        $link=$GLOBALS['cfg']['paths']['rel'].$url;
                break;
                case("URL"):
                        $link=$url;
                break;
                default:
                        $link=$GLOBALS['cfg']['paths']['rel'].$url;
                break;
        }
       
   echo '<div><a href="'.$link.'"';
   if($url==basename($_SERVER['PHP_SELF']))
      echo ' class="menuon"';
   echo '>'.substr($page,3).'</a>';
   echo '</div>';
endforeach;
 

Re: need to add outside URL link within array

Posted: Wed Apr 14, 2010 7:17 am
by kevinwinters
Thank you roders.

Re: need to add outside URL link within array

Posted: Wed Apr 14, 2010 7:19 am
by roders
You're welcome mate.