I take dark chocolate (72% or more) which requires high temps to melt than lighter chocolates. put the chocolate inside my pack (it gets some insulation from outside heat) right next to my playtpus water bladder which normally has water which is cooler than air temp. I keep my chocolate in a plastic bag so if it does melt, the mess is contained. If it's melted, I will often put the bag in a stream until it cools enough to harden.
When it's going to be really hot I switch to M&M. The chocolate isn't as tasty, but as the ad says... melts in your mouth, not on your hands.