How to get image_pair in a foreach loop

Hey!!



i am struggling with this. I am trying to get from inside a foreach loop in a tpl file the image_main_pair information for categories where the category_id information is known, See the red comment below:



i am using this include:



{include file=“common_templates/image.tpl” show_detailed_link=false object_type=“subcategory” images=[color=#ff0000][Here i need the category main_pair array and i don't have it, instead i have the category id][/color] no_ids=true class=“cm-thumbnails” show_thumbnail=“Y” image_width=“100” image_height=“”}





any one can give me a clue? I'll Appreciate it





Thanks

do it in the PHP side of things (in the controller) and then reference it in the template. Usually a bad idea to do data fetching in the presentation layer.

ok! got it. Now one more question:



whats the best way to pass a variable from the tpl to the php controller. I am ware of the other way around through assign->view but not this one??

You can't other than using PHP tag. But I would NOT recommend that. You are approaching the problem backwards.

Why don't you describe what you are trying to accomplish (not how you are doing it) and maybe we can help get you on the right track.

Ok i am modifying the drop down menu to show just 1st and 2nd level categories with the thumbs on top of it. The problem with this is that since menu is on top of all pages i have to make it independent of controllers, in other words it needs to display in all controller/modes combination, where don't have more than the variable items, items1 and items2 in blocks/topmenu_dropdown.tpl. Then i need to get the image URL to place the thumb on top of the subcategory but $items does not contain image_pairs information in this template to be able to pull out the info.



Then following your advice i would create a php script to be able to pull out this info from the data base in the my_changes controller, but then again how do i send the variable to the function in php???



i hope you get the idea

Got it sorted out!



The most important thing here i think, is the fact that (As far as i can See) the only way to get tpl to interact with an existing PHP core function is through this format, for example for my case:



{assign var=“cat_main_pair” value=$item2.category_id|fn_get_image_pairs:category:M}



Run this on the tpl and you'll get your image pair information in $cat_main_pair, then you can get the thumbnail running:



{include file=“common_templates/image.tpl” show_detailed_link=false object_type=“subcategory” images=$cat_main_pair no_ids=true class=“cm-thumbnails” show_thumbnail=“Y” image_width=“100” image_height=“”}





I understand your concern tbirnseth but trying to run this in the controller becomes difficult for me as i do not know how to pass the category_id variable to the PHP controller from the TPL, unless we implement the whole controller:mode thing… Your thought on this will be appreciated.

[quote]

unless we implement the whole controller:mode thing… Your thought on this will be appreciated.

[/quote]

Not knowing what you are trying to do makes it hard to advise (as stated above). But your statement is in fact the proper way to do it.