templates and directive implementation