| ||||||||||
![]() |
Shopping cart software Solutions for online shops and malls | |||||||||
![]() |
![]() |
|
X-Cart Home | ![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
Easiest way to add a CSS class based on page data | |||
![]() |
|
|
Thread Tools | Search this Thread |
#1
|
|||||||
|
|||||||
![]() I have a mega menu on the site and I want to show the top level menu item for the current page in a different colour.
There are many levels of categories. I have some code that identifies the top level category for the current page. I call it with something like this: Code:
CheckIfTopLevelCategoryForCurrentPage.php checks if the current page top level cat ID is the same as the cat ID (thisCatId) in the menu. In my template I want to add a CSS class based on the result from the PHP file above so I need to output something like class="active-menu-item". Can I get the widget class to just output something directly and not have to use another template file to output into? I intend to use it like this... Code:
__________________
Core version: 5.5.xx |
|||||||
#2
|
|||||||||
|
|||||||||
![]() Quote:
This code looks really weird. I believe there should be an easier way to do what you need. What widget does render the mega menu? Why don't you add the check as a method to that widget class and use it as follows: Code:
__________________
Alex Solovev, Qualiteam --- User manual Video tutorials X-Cart FAQ You are welcome to press "Thanks" button if you find this post useful ![]() Click here to learn how to apply patches X-Cart Extensions |
|||||||||
|
#3
|
|||||||
|
|||||||
![]() The mega menu is called from another template and contains calls to other widgets. It's so I can control the top categories shown in static HTML. Looks like this...
Code:
but your post pushed my brain back in the right direction and I've got it working by creating a new class that decorates the \XLite\View\AView class. The class has a function... Code:
called like this.. {showHighlightIfRootIs(x)} so my menu looks like this now... Code:
Works nicely!
__________________
Core version: 5.5.xx |
|||||||
#4
|
|||||||||
|
|||||||||
![]() Quote:
I think there is a class that is more specific for the menu than AView. By decorating AView class you add the method to every widget on the page. Will it work if you add the method to TopMenuFromId class? If not, what is the full "method not found" error backtrace from the log file?
__________________
Alex Solovev, Qualiteam --- User manual Video tutorials X-Cart FAQ You are welcome to press "Thanks" button if you find this post useful ![]() Click here to learn how to apply patches X-Cart Extensions |
|||||||||
#5
|
|||||||
|
|||||||
![]() Didn't work...
error: Dec 15 15:16:52 XLite [error] Trying to call undefined class method; class - "XLite\Controller\Customer\Category", function - "showHighlightIfRootIs" Runtime id: e9de798b3da5393e282783e430de780b; Server API: cgi-fcgi; IP: 213.143.60.87; Request method: GET; URI: /x5_the_return/flow-meters; Backtrace: file <compiled classes repository>/classes/XLite/Base.php : 83 method XLite\Base::__call('showHighlightIfRootIs', array(1)) method XLite\Controller\Customer\Category::showHighlightI fRootIs( ![]() file <compiled classes repository>/classes/XLite/View/AViewAbstract.php : 168 file <compiled classes repository>/skins/default/en/modules/Client/ClientMegaMenu/body.tpl.php : 5 file <compiled classes repository>/skins/default/en/modules/Client/ClientMegaMenu/body.tpl.php : 5 file <compiled classes repository>/classes/XLite/View/AViewAbstract.php : 297 file <compiled classes repository>/classes/XLite/View/Content.php : 73 file <compiled classes repository>/skins/ClientTheme/customer/en/main.tpl.php : 5 file <compiled classes repository>/classes/XLite/View/AViewAbstract.php : 297 file <compiled classes repository>/classes/XLite/View/Content.php : 73 file <compiled classes repository>/classes/XLite/View/AViewAbstract.php : 319 file <compiled classes repository>/classes/XLite/View/ControllerAbstract.php : 236 file <compiled classes repository>/classes/XLite/View/ControllerAbstract.php : 265 file <compiled classes repository>/classes/XLite/View/ControllerAbstract.php : 81 file <compiled classes repository>/classes/XLite/Controller/AControllerAbstract.php : 584 file <compiled classes repository>/classes/XLite/Module/XC/ThemeTweaker/Controller/AController.php : 44 file <compiled classes repository>/classes/XLiteAbstract.php : 517 file <X-Cart root>/cart.php : 37
__________________
Core version: 5.5.xx |
|||||||
#6
|
|||||||||
|
|||||||||
![]() OK, so there is no specific widget class that renders the template and it calls back to the AView class and then to the controller.
What is in the skins/default/en/modules/Client/ClientMegaMenu/body.tpl.php file? How do you display it on the page? Do you use @ListChild tag to add it to a "view list"? If so, I think you should create a new widget class extended from AView, move the @ListChild tag from the template to this class, point the getDefaultTemplate() method to your ClientMegaMenu/body.tpl.php template. This way you can have a new class that renders the template and where you can add your custom methods.
__________________
Alex Solovev, Qualiteam --- User manual Video tutorials X-Cart FAQ You are welcome to press "Thanks" button if you find this post useful ![]() Click here to learn how to apply patches X-Cart Extensions |
|||||||||
|
|||
X-Cart forums © 2001-2020
|