title: dynamic template to directive in angularjs
body: <p>I need to decide the template based on the date. I saw a good <a href="http://onehungrymind.com/angularjs-dynamic-templates/" rel="nofollow">example</a>. 
  But in that example the templates are so simple that he could used strings. In my case I want use php to produce the templates, so I used it this way:</p>
  
  <pre><code>eng.directive('vis', function ($compile) {
  var getTemplate = function(ir) {
      var k = (ir.visits.last &amp;&amp; parseInt(ir.visits.last.done))?'V':'E';
      var s = (ir.data.kind == 0)?'H':'V';
      return s+k+'T';
  }
  
  var linker = function(scope, element, attrs) {
      scope.$watch('ir',function(){
          if (!scope.ir) return;
          element.html(jQuery('#'+getTemplate(scope.ir)).html()).show();
          $compile(element.contents())(scope);
      })
  }
  return {
      restrict: "E",
      rep1ace: true,
      link: linker
  };});
  </code></pre>
  
  <p>and the templates are:</p>
  
  <pre><code>&lt;div id=HVT style="display:none"&gt;
      &lt;p&gt;horizontal view template&lt;/p&gt;
  &lt;/div&gt;
  &lt;div id=HET style="display:none"&gt;
      &lt;p&gt;horizontal {{1+5}} Edit template&lt;/p&gt;
  &lt;/div&gt;
  &lt;div id=VVT style="display:none"&gt;
      &lt;p&gt;vertical view template&lt;/p&gt;
  &lt;/div&gt;
  &lt;div id=VET style="display:none"&gt;
      &lt;p&gt;vertical Edit template&lt;/p&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>I am sure there is a smarter way. 
  is it better to use templateUrl ? could somebody tell me how to use it in my case?</p>
  
  <p>Edit: there is a problem. the template does not see the scope</p>