I guess everything under -------- is the update to your post (next time, just reply instead).
You mistake is probably {undef}, witch undefines every variable in the current/same namespace (basically all variables earlier set with def). So you should have written : {undef $pagelayout_node}