The "Legend of the Candy Cane" poem comes from the book by the same name from Lori Walburg. It features a girl named Lucy who learns the poem and shares it with others, bringing her town together to learn the meaning of Christmas.
The "Legend of the Candy Cane" poem notes the symbolism of the candy cane's red and white stripes, with the red stripes symbolizing the blood of Jesus, and the white stripes symbolizing his purity and lack of sin. The shape of the candy cane, which is like a staff, symbolizes Jesus' as a shepherd.
There is another explanation for the "Legend of the Candy Cane." This particular version says that a German choirmaster decided to give children candy sticks during Christmas Eve mass in an effort to keep them quiet. To justify this, he asked the candy maker to put a bend in the candy stick to remind them of the shepherd's staff, and to make them white in color to remind them of the sinless life of Jesus.
Churches and schools tend to not focus on either of the stories, but rather teach only the poem. Common practice is for each child to attach a copy of the poem to two candy canes, keeping one, and giving the other away in order to spread the story and teach about Jesus.