Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

SmartyMenu 1.0 released
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Smarty Forum Index -> Add-ons
View previous topic :: View next topic  
Author Message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Fri Oct 29, 2004 10:34 pm    Post subject: SmartyMenu 1.0 released Reply with quote

SmartyMenu is a tool for creating CSS driven dropdown menus. Assign your menu content, define your stylesheet, *poof*, you've got menus.

The technique deployed with SmartyMenu is based off of suckerfish dropdowns by Patrick Griffiths and Dan Webb. They are basically 100% CSS driven menus with a light javascript footprint for browsers that are not 100% CSS compatible. They can be infinitely nested in theory, although each level of nesting requires an added style definition. SmartyMenu example stylesheets handle four levels by default, and can easily be tweaked to handle more.

Getting CSS menus to work cross-platform is quite a daunting task. The stylesheets that come with SmartyMenu are fairly good at rendering across browsers, but not perfect! Please don't expect me to debug the cross-browser bugs, but OTOH please share your findings if you get things to work!

This is release 1.0, I'm hoping to get some help from the CSS gurus out there that have worked with this stuff before, hopefully we can build a library of stylesheets that look good and work good for most browsers. As the ratio of browsers of CSS compliant browsers gets higher, the need to support the b0rken ones (*cough*IE*cough*) will hopefully fade into the past.

http://www.phpinsider.com/php/code/SmartyMenu/

suckerfish homepage:

http://www.htmldog.com/articles/suckerfish/dropdowns/

Have fun, and have a happy Halloween while you're at it Wink


Last edited by mohrt on Thu Jan 27, 2005 8:59 pm; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
kills
Smarty Elite


Joined: 28 May 2004
Posts: 493

PostPosted: Sat Oct 30, 2004 6:52 pm    Post subject: Reply with quote

Hi monte,

i `ve got a few idears for your menu.

What about a Method which sets several Item attributes?

instead of

[php:1:e2dbb48989]
SmartyMenu::setItemText($item, 'Google News');
SmartyMenu::setItemLink($item, 'http://news.google.com/');
SmartyMenu::setItemClass($item, 'subnav');
[/php:1:e2dbb48989]

something like this?

[php:1:e2dbb48989]
// returns a item or probably append it promptly to the menu?
// style as an optional attr?
SmartyMenu::createItem( 'Google News', 'http://news.google.com/', 'subnav');
[/php:1:e2dbb48989]


What about assigning the item to the menu while init it?

instead of
[php:1:e2dbb48989]
SmartyMenu::initItem($item);
SmartyMenu::setItemText($item, 'Google');
SmartyMenu::setItemLink($item, 'http://www.google.com/');
SmartyMenu::addMenuItem($menu, $item);
[/php:1:e2dbb48989]

do it like this?

[php:1:e2dbb48989]
SmartyMenu::initItem($menu, $item);
SmartyMenu::setItemText($item, 'Google Groups');
SmartyMenu::setItemLink($item, 'http://groups.google.com/');
[/php:1:e2dbb48989]


I think the template functions should be namend in a different way:


instead of
Code:
<html>
    <head>
    {menu_init css="/css/menu.css"}
    </head>
    <body>
    Menu Test
    <p>
    {menu data=$menu}
    </p>
    </body>
    </html>


so...?

Code:
<html>
    <head>
    { menu_css file="/css/menu.css"}
    </head>
    <body>
    Menu Test
    <p>
    {menu data=$menu}
    </p>
    </body>
    </html>



for all monte-Toolls: Smile

What about a little if-case which exits the the code if a session is not started?
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Sat Oct 30, 2004 8:11 pm    Post subject: Reply with quote

kills wrote:

something like this?

[php:1:9aa3c78b63]
// returns a item or probably append it promptly to the menu?
// style as an optional attr?
SmartyMenu::createItem( 'Google News', 'http://news.google.com/', 'subnav');
[/php:1:9aa3c78b63]



I had messed with that idea, but it gets out of hand as soon as you want to add more types of information, especially if some of it is optional. This seemed most flexible.

kills wrote:


What about assigning the item to the menu while init it?



Hmm, I suppose that could save a step.

kills wrote:


I think the template functions should be namend in a different way:

Code:
<html>
    <head>
    { menu_css file="/css/menu.css"}
    </head>
    <body>
    Menu Test
    <p>
    {menu data=$menu}
    </p>
    </body>
    </html>




the *_init naming covention lends itself to other uses, such as including javascript files and such at a later date. This also follows the naming conventions of the other tools.

kills wrote:



for all monte-Toolls: Smile

What about a little if-case which exits the the code if a session is not started?


That could be done, although this one has no session requirement Wink

Monte
Back to top
View user's profile Send private message Visit poster's website
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Sat Oct 30, 2004 10:02 pm    Post subject: Reply with quote

The following are observations and opinions only, not critical comments....

I sometimes wonder about the point of the *_init functions since they merely wrap a single HTML-type include tag. So I don't use them Smile

So I'm against passing the menu data to the init function.

As for the setItem* methods, I tend to prefer having such things structured as as single method (say setItem) that takes a parameter indicating the type [eg: SmartyMenu::setItem('Class', $item, 'subnav')] because I don't like endless amounts of function points and the associated duplicated code segments. I suppose, though, that that kind-of goes against the PHP mantra of being able to plug a specific function name into a manual search to find out what is happening. I'll probably preparing my data structures outside of the menu class and just pass in a complete array anyways Wink

Finally, I'm wondering if a tiny bit of generalized framework is in order that would enable the various Addons to be pulled together (but only loaded on demand) so as to avoid duplication of code. Does anyone else think that is worthwhile or is it better to have each of the addons rely only on Smarty and Not-Yet-Another-Class?
Back to top
View user's profile Send private message
kills
Smarty Elite


Joined: 28 May 2004
Posts: 493

PostPosted: Sun Oct 31, 2004 9:12 am    Post subject: Reply with quote

mohrt wrote:

kills wrote:



for all monte-Toolls: Smile

What about a little if-case which exits the the code if a session is not started?


That could be done, although this one has no session requirement Wink

Monte


I didnt took a look in the code.

But i think it would be nice to save the menu data in a session, so you have to init the whole thing only one time. (e.g. when using smartyMenu with a structure from a DB)

Edit:

Why did you take this:

Code:

<script type="text/javascript">
<!--//--><![CDATA[//><!--//--><!]]>
</script>


what does this pattern mean?
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Wed Nov 10, 2004 10:24 pm    Post subject: Reply with quote

SmartyMenu as been updated in CVS to include loadMenu(), saveMenu() and resetMenu() methods for storing menus in the PHP session.
Back to top
View user's profile Send private message Visit poster's website
Isidor128
Smarty Regular


Joined: 27 Jul 2004
Posts: 35
Location: France

PostPosted: Sat Nov 20, 2004 9:28 pm    Post subject: Reply with quote

boots wrote:
...
Finally, I'm wondering if a tiny bit of generalized framework is in order that would enable the various Addons to be pulled together (but only loaded on demand) so as to avoid duplication of code. Does anyone else think that is worthwhile or is it better to have each of the addons rely only on Smarty and Not-Yet-Another-Class?


Yes I think thzt would be the best way

Regards
Back to top
View user's profile Send private message Visit poster's website
talo
Smarty Rookie


Joined: 18 Oct 2005
Posts: 16

PostPosted: Tue Nov 15, 2005 9:54 am    Post subject: I second that Reply with quote

Hi,

Boots wrote:

Quote:
...
Finally, I'm wondering if a tiny bit of generalized framework is in order that would enable the various Addons to be pulled together (but only loaded on demand) so as to avoid duplication of code. Does anyone else think that is worthwhile or is it better to have each of the addons rely only on Smarty and Not-Yet-Another-Class?


I totally think there should be something like that.

An interface where you can choose what you want to be on your template out of the large varaiety of plugins and add-onns etc.

just as an example: pagination and column sort in a grid like result of a SQL query.

also to take it a bit further i think that the plugins should each have an interface with which ppl can easelly choose different fuctionality, and custimize, and that info will then be saved in an "init" style function or whatever.

i find it sometimes with all the extensive support it is still quite dificult to fiddle with these plugins to get them to do very specific things for a particular project.

also the reason i mentioned pagination and column sort is because just looking at the SmaryPagination plugin gave me a fright.
i got this other pagination plugin, i cant remember who was it that made it, but its very very simple and it works GREAT!!! and very easy to modify.

but i do most definitlly appreciate the good work, i use a lot of this stuff.

T.
Back to top
View user's profile Send private message
TGKnIght
Smarty Junkie


Joined: 07 Sep 2005
Posts: 580
Location: Philadelphia, PA

PostPosted: Sat Jan 14, 2006 3:36 am    Post subject: Reply with quote

Awesome plugin Smile

I was wondering what the proper way to customize the menu is?

For example, the immediate thing I saw was a need for graphical indicator showing which menu options had sub items.

My solution was to edit your menu plugin and comment out the htmlspecialchars() function on the $element['text'].

Is there a better way to do this? I would like to expand this so that I can put little graphics next to key options on the menu, for example the login/logout link should have a little lock graphic or something of that nature.

Maybe I am missing the official way, or one needs to be implemented? Smile

Thanks as always for your awesome work,
Owen
Back to top
View user's profile Send private message Visit poster's website
bob88
Smarty n00b


Joined: 02 Feb 2006
Posts: 3

PostPosted: Mon Feb 13, 2006 10:41 am    Post subject: Reply with quote

Hey,

A simple question, is possible to freeze the link where we are ?

Thanks


Last edited by bob88 on Wed May 05, 2010 10:55 pm; edited 1 time in total
Back to top
View user's profile Send private message
TGKnIght
Smarty Junkie


Joined: 07 Sep 2005
Posts: 580
Location: Philadelphia, PA

PostPosted: Mon Feb 13, 2006 3:25 pm    Post subject: Reply with quote

This is something I have been trying to figure out myself... The problem is once the menu is saved to $_SESSION, it doesn't really get reparsed, so saving the link in the menu array won't work...

I have written a function that recursively parses the menu searching for a matching link, so that I can utilize the sub-menu grouping for a list of toolbar links...

Unfortunately it's not accurate as there are occasions where I will have the same link at different locations on the menu..

I think that if the menu structure was saved in an associative array it would make it much more accessible..
_________________
Smarty site with one index.php controller file
Working with MySQL and Smarty
SmartyColumnSort
Custom Smarty Javascript Debug Template
Back to top
View user's profile Send private message Visit poster's website
anthony_ksw
Smarty Rookie


Joined: 19 Aug 2005
Posts: 18

PostPosted: Tue Feb 14, 2006 1:58 pm    Post subject: Problem with SmartyMenu Reply with quote

I can't get the menu working, I tried for so many times. I only got the plain text tho. Could anyone help me out please.

Here is my php code (sample from the demo):
<?php

define ("TEMPLATES_PATH",$full_path . "templates");
define ("TEMPLATES_C_PATH",$full_path . "templates_c");
define ("CONFIGS_PATH",$full_path . "configs");
define ("CACHE_PATH",$full_path . "cache");

session_start();
require('Smarty/libs/Smarty.class.php');
require('Smarty/libs/SmartyMenu.class.php');


$smarty =& new Smarty;

// attempt to load the menu from the session
if(($menu = (SmartyMenu::loadMenu('mymenu'))) === false) {

// initialize your menu
SmartyMenu::initMenu($menu);

// first menu item
SmartyMenu::initItem($item);
SmartyMenu::setItemText($item, 'Yahoo');
SmartyMenu::setItemLink($item, 'http://www.yahoo.com/');
SmartyMenu::addMenuItem($menu, $item);

// second menu item
SmartyMenu::initItem($item);
SmartyMenu::setItemText($item, 'Google');
SmartyMenu::setItemLink($item, 'http://www.google.com/');
SmartyMenu::addMenuItem($menu, $item);

// third menu item
SmartyMenu::initItem($item);
SmartyMenu::setItemText($item, 'Netscape');
SmartyMenu::setItemLink($item, 'http://www.netscape.com/');
SmartyMenu::addMenuItem($menu, $item);

// save the menu into the session
SmartyMenu::saveMenu('mymenu', $menu);
SmartyMenu::loadMenu();

}

$smarty->assign('menu', $menu);

$smarty->display('index.tpl');

?>

index.tpl :
<html>
<head>
{menu_init}
{menu_init css="/css/menu.css"}

</head>
<body>
Menu Test
<p>
{menu data=$menu}
</p>
</body>
</html>

I have put the files in the right directory and I just can't get the java script load up, i think.
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Tue Feb 14, 2006 2:50 pm    Post subject: Reply with quote

Compare your HTML output (view browser source) with the output from the demo, see if it coincides. Check the javascript console too.
Back to top
View user's profile Send private message Visit poster's website
anthony_ksw
Smarty Rookie


Joined: 19 Aug 2005
Posts: 18

PostPosted: Thu Feb 16, 2006 12:11 am    Post subject: Reply with quote

Thanks! Got it working now. But I want to set the navigation bar to the center of the web page. can anyone help me out?
Back to top
View user's profile Send private message
TGKnIght
Smarty Junkie


Joined: 07 Sep 2005
Posts: 580
Location: Philadelphia, PA

PostPosted: Thu Feb 16, 2006 12:30 am    Post subject: Reply with quote

All visual changes to your menu need to be done with CSS.

To center a menu, let's place your menu output inside a

Code:

<div id="menu"></div>


Then in your CSS I think you should just be able to do

Code:

#menu {
   text-align : center;
}

_________________
Smarty site with one index.php controller file
Working with MySQL and Smarty
SmartyColumnSort
Custom Smarty Javascript Debug Template
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Add-ons All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP