Looping through Timber\Menu in PHP. Possible? I'm getting weird results. #2764
-
Hi, I'm trying to loop through a Timber menu in PHP. My aim is to extract the sibling submenu items for the active page. It should be easy but the results I'm getting are very strange. Firstly, if I print_r() the items in the menu obj the size is 400KB:
That's all good. This returns an array containing Timber\MenuItem Objects. Now I'd like to loop through these objects but if I print_r() the individual objects my output is now over 13MB and I seem to be displaying the whole menu with each loop:
That just seems very strange. Changing the print_r() to print_r($item->master_object) does bring the output down to normal again, but without the children I need. Changing to print_r($item->children) gives me the huge 10MB+ file size. Is there a simple way for me to get an array of the children of each menu item? Thanks in advance. John.. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Just to add to this. I think it may just be an issue with how PHP's print_r() works with the Timber\Menu object. I've managed to successfully do what I need by using the following loop:
|
Beta Was this translation helpful? Give feedback.
Just to add to this. I think it may just be an issue with how PHP's print_r() works with the Timber\Menu object. I've managed to successfully do what I need by using the following loop: