Jump to content

Linking to a Tool in Nav Menu ?


Nik Grey

Recommended Posts

Brian, I have just noticed something - when I paste this into the Snippet code area:

 

{php}
$lettering_tool_branch = array('url' => $GLOBALS['storeURL']."/index.php?_a=letter", 'name' => "Lettering Tool");
$GLOBALS['smarty']->assign('BRANCH', $lettering_tool_branch);
$navigation_tree .= $GLOBALS['smarty']->fetch('templates/element.navigation_tree.php');
$navigation_tree = preg_replace('#<li>.*title="Lettering".*</li>#s','',$navigation_tree);
$GLOBALS['smarty']->assign('NAVIGATION_TREE', $navigation_tree);
{/php}
 

 

When I save it - clear the cache and go back to check the code I notice it appears as this:

 

{php}
$lettering_tool_branch = array('url' => $GLOBALS['storeURL']."/index.php?_a=letter", 'name' => "Lettering Tool");
$GLOBALS['smarty']->assign('BRANCH', $lettering_tool_branch);
$navigation_tree .= $GLOBALS['smarty']->fetch('templates/element.navigation_tree.php');
$navigation_tree = preg_replace('#.*title="Lettering".*#s','',$navigation_tree);
$GLOBALS['smarty']->assign('NAVIGATION_TREE', $navigation_tree);
{/php}

 

 

The <li> and </li> are missing ?

 

But I added the 'U' regardless and it's now looking like this:

 

missing1.jpg

Link to comment
Share on other sites

Stupid Sanitation!

 

In the file /classes/sanitize.class.php, line 30, add 'php_code' and a comma to the array:

private static $exempt = array('php_code', 'description', ....

 

CubeCart is sending the content through a PHP filter that strips out certain, supposedly dangerous, things.

 

@Al, please add the snippet['php_code'] key to the array of exempt keys in the sanitize class.

Link to comment
Share on other sites

There must have been other characters that I missed as just pasted the original code in again and its much better - that >Lettering menu item that did nothing has gone.

 

So just adding the above 'php_code', worked :)

 

My Mugs are missing from the menu though..lol.

Link to comment
Share on other sites

Well, it seems that discovering the regex pattern code to do this properly will take me about a week to learn. So let's try a different approach.

 

We will explode the string at the <li> sequence into an array, look for the array element with Lettering, remove that array element, then implode the array back into a string.

{php}
$lettering_tool_branch = array('url' => $GLOBALS['storeURL']."/index.php?_a=letter", 'name' => "Lettering Tool");
$GLOBALS['smarty']->assign('BRANCH', $lettering_tool_branch);
$navigation_tree .= $GLOBALS['smarty']->fetch('templates/element.navigation_tree.php');
$navigation_tree_array = explode("<li>", $navigation_tree);
foreach($navigation_tree_array as $navigation_tree_key => $navigation_tree_val) {
  if (strpos($navigation_tree_val, 'title="Lettering"') !== false) unset($navigation_tree_array[$navigation_tree_key]);
}
$navigation_tree = implode("<li>",$navigation_tree_array);
//$navigation_tree = preg_replace('#<li>.*title="Lettering".*</li>#sU','',$navigation_tree);
$GLOBALS['smarty']->assign('NAVIGATION_TREE', $navigation_tree);
{/php}
Link to comment
Share on other sites

Good Lord, it only WORKS !

 

I want to understand how though, I will re-visit this first thing today.

 

missing2.jpg

 

I can add things to the Cart :) that's what I mean by working as well as the products appearing in the Nav bar :) most pleased - Thanks Brian.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...