#221 Fixed variable substitution and added target_page_id attr

@Chrico pls review, fix remaining problems, and merge