maba Posted December 20, 2012 Share Posted December 20, 2012 Hi All, with this I start to create this menu where: not show all root children show all company children show products following sectors/applications way show new label for the newest products (see Products->Water->Derivation) (I would) not show applications without products (see Products->Gas->Derivation) show contacts (todo) show galleries (more complex than products, based on category, static sample now) (todo) show blog children (done) multi language In attach my pages structure. My code: https://gist.github.com/4348501 Now: how to clear this code? How DRY it (e.g. $class declaration)? How optimize it? Thanks, Marco Link to comment Share on other sites More sharing options...
netcarver Posted December 20, 2012 Share Posted December 20, 2012 @moreweb any chance you could put that code in a gist over on github, or on paste-bin or something? Removing the leading whitespace will also make it more readable. I can't make head nor tail of it on the forum Link to comment Share on other sites More sharing options...
maba Posted December 20, 2012 Author Share Posted December 20, 2012 Hi netcarver, you're right. I've created a gist Thanks Link to comment Share on other sites More sharing options...
Soma Posted December 21, 2012 Share Posted December 21, 2012 One word: MarkupSimpleNavigation Be creative. 1 Link to comment Share on other sites More sharing options...
maba Posted December 21, 2012 Author Share Posted December 21, 2012 Soma, if you say that I can use the module to optimize the menu logic.. I totally misunderstand it. Link to comment Share on other sites More sharing options...
maba Posted January 2, 2013 Author Share Posted January 2, 2013 Hi everybody.. Soma, I've some problems with the module. Ok, I can delete my Products page (and children) but how I can inject my "edited" Products menu? Can you post an example? Thanks! Marco Link to comment Share on other sites More sharing options...
Soma Posted January 3, 2013 Share Posted January 3, 2013 Sorry to not get back any sooner. What do you mean to clean up the code and make it dry? It actually looks good and clean. I don't think you can easily reduce or simplify with the special case of menu you got. I havent looked closely at your code before when i posted that. I dont see an easy way to use my module to create this sort of navigation. only partial at best. Sorry to confuse you. I think nobody really poped in to help you because it is already good and people dont like to clean up or code it for you. I guess you know why. Ive done it occasionally and only because ive thought the requester has no clue. So you come with a big list of how it should work and it looks as you want it to someone else make it for you. That most likely wont work here. If you post a specific question of something you cant get to work Im sure somebody will try to help. Again your code looks fine to me and you get the most out of it with simple foreachs. I don't think theres much to dry here. Link to comment Share on other sites More sharing options...
maba Posted January 3, 2013 Author Share Posted January 3, 2013 Soma, thanks for the answer. What do you mean to clean up the code and make it dry? It actually looks good and clean. I don't think you can easily reduce or simplify with the special case of menu you got. Is enough. My fear is to don't use all the features that PW give us. When you said that I can use MarkupSimpleNavigation I thinked that probably I don't understand its potential. I search far and wide in the forum but I don't found (module) examples that can help me. (I would) not show applications without products (see Products->Gas->Derivation) (todo) show galleries (more complex than products, based on category, static sample now) These are the open points.. other things is already done with the posted code. I've some problems with the first, I'll try to fix it. So you come with a big list of how it should work and it looks as you want it to someone else make it for you. That most likely wont work here. Sorry, isn't my goal. Again.. thanks. Marco Link to comment Share on other sites More sharing options...
Soma Posted January 3, 2013 Share Posted January 3, 2013 Fact is your code is perfectly fine for what it archives. You'll not find any modules that could help you doing it, at best the MarkupSimpleNavigation. It is well for quickly rendering straight nested navigations. You can overwrite with you own templates and selector (global) etc, as the manual shows. However it is not suited for things like you do with products and categories as it just traverses the page tree or parts of it. For more complex navigation the PW API and the hierarchical structure makes it very easy to construct them the way you did. I wouldn't start putting it to pieces with abstraction and functions for this menu. You problem with navigation not showing when no products found would be easy with moving the output after iterating the products and test if they're linked. Then echo only if any found. For example: foreach($applications as $a) { $prod_str = ''; foreach($products as $p) { if(!$p->applications->has($a)) continue; if(!$p->sectors->has($s)) continue; $span = $p->new == 1 ? " <span class='orange sub-menu-title'>" . $this->_('novita') . "</span>" : ""; $prod_str .= "<li><a href='$p->url'>$p->title$span</a></li>"; } if($prod_str){ echo "<li><a href='$a->url'>$a->title</a><ul class='sub-menu'>$prod_str</ul></li>"; } } 1 Link to comment Share on other sites More sharing options...
maba Posted January 4, 2013 Author Share Posted January 4, 2013 Yes Thanks Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now