0

I'm trying to call for a Twig template _template from a Twig template, particularly from within AngularJS <script type="text/javascript"></scirpt> tags. A console log says, that the file was not found on the server with status of 404. Using {% include '' %} or {% embed '' %}interferes with AngularJS somehow. Does any way around exists to access that Twig template, without breaching the security?

Troubleshooting part of js:

$mdDialog.show({
  templateUrl: '_template',
})
Dominik Krulak
  • 1,562
  • 14
  • 27
  • Can you give me a general idea of what's hanging out in the file.twig? Also- what issues is it giving you with the include/embed tags? – Dustin C Jan 15 '16 at 00:46
  • The console log says that an error is coming from angularjs. The file.twig has entries and some math to get a reviews and ratings work. It's working fine without including template path within script tags. So I thought maybe to hardcode the path? – Dominik Krulak Jan 15 '16 at 07:04

1 Answers1

5

Not sure exactly what you trying to do here? Call a Twig template from Angular?

Twig is a server side technology, Angular is getting parsed on the client side. The only way Craft is going to parse a Twig template is when it encounters a URL.

Instead of calling the Twig template directly, you call the URL, which could match a template. Inside templates, make a folder like angular-views and then inside that put a file called md-dialog.twig. From the front end, now you can call it from Angular like http://example.com/angular-views/md-dialog (the .twig is optional).

If you're trying to use Angular inside of a Twig template, you may want to use something like {% verbatim %} and then put your JS/Angular templating between those tags to make sure Twig doesn't touch any of it.

RitterKnight
  • 6,582
  • 14
  • 24
  • 1
    I wanted to call a Twig template from a Twig template from within <script type="text/javascript"></script> tags. So I built the path to a file, which was in a folder with underscore("_"). That was my mistake, as It didn't occur me right away, that folders/files are hidden from direct access with underscore at the beginning. So It was throwing me a status of 404. Than I tried Twig's tags {% included %},{% embed %} and {% verbatim %} which gave me an AngularJS error. Glad you turned in on me with your answer. – Dominik Krulak Jan 16 '16 at 12:01
  • Good deal - glad it was helpful! – RitterKnight Jan 16 '16 at 20:41