Added state switches (first/last instance )

Added a state variables for use in switches that indicate wither this
is first or last instance of a template