1

I have a page in Craft (2.x) that displays several links and I was able to find which twig file had those links by searching the code base of twigs. Those links point to some Angular code with links like this:

/support/give?source=

By trial and error, I discovered that the Angular code is invoked as part of a twig file in craft/templates/_views/ The original conundrum was there were two "give" files: give.twig and give-new.twig and I didn't know which one was the actual twig invoked. By trail and error again, I determined it was using the give-new.twig by changing the template. But for the life of me, I cannot figure out how THAT twig is being invoked. I scanned for "give-new" in the code, both craft and Angular and I searched in Settings, Routes and Web Content for any reference to it but I cannot figure out how a URL like /support/give maps to the give-new.twig file.

So the question is: How do I know which twig is invoked by a URL? I am pretty sure that there isn't any Angular code doing this, the Angular code bundle references are in the twig file, but how that twig is invoked is a mystery. Where do I start in finding the reference?

  • Check the config/routes.php file, see if it shows up in there. – Lindsey D Aug 22 at 16:14
  • I checked the routes.php file and it has no entries except return array(); – Pete Helgren Aug 26 at 15:22
  • Should have checked Routes in settings....I would have found it there. – Pete Helgren Aug 26 at 19:59
  • Ah... you said "I searched in Settings, Routes", so I thought you had already checked that. – Lindsey D Aug 26 at 20:02
  • Wow! True...so I am not sure why I didn't see it. Sorry. Should have walked through what I said I did a second time before I posted. – Pete Helgren Aug 27 at 23:00
2

You could use this variable to get the template name: {{ _self.getTemplateName() }}

Put it at the top of all your template files:

<!-- {{ _self.getTemplateName() }} -->

And then for every template called it should have the commented out template name.

In Craft 3, there's a nice plugin called "Template Comments" which is great for this... But I don't see a version for Craft 2.

  • Thanks. I know what the template name is, it's give-new.twig. The issue is, I can't tell HOW and WHERE that particular twig is invoked. IOW, why is give-new.twig invoked and not the give.twig invoked even though both are in the same folder. Or, said another way, if I decided to create give-brand-new.twig how would I get that twig to display? – Pete Helgren Aug 26 at 15:27
  • Hmm. I see, i was thinking it'd give context, like looking in the code so see what it's wrapped in. like if you're reading down the compiled page source, you'd see ... <!-- parent file --> ... <!-- give-new file --> ... <!-- other embedded file --> etc. And then you'd be able to see what's wrapped around it, so you'd ave a better idea where to look. – SamC Aug 26 at 18:55
  • Uh, additional thought. If it's not in your template code, maybe it's in your database - like there's a global or an entry field that that has "give-new" as text in it. – SamC Aug 26 at 19:00
  • OK...I see what you are saying in your earlier comment. Not sure if help but I may try it. Just to see what would happen, I just deleted the twig to see what would show up in the logs. This is what I see: 2019/08/26 19:25:06 [error] [exception.Craft\HttpException.404] Craft\HttpException in craft\app\controllers\TemplatesController.php:72 Stack trace: #0 [internal function]: Craft\TemplatesController->actionRender('_views/give-new', Array) #1 craft\app\framework\web\actions\CAction.php(109): ReflectionMethod->invokeArgs(Object(Craft\TemplatesController), Array) – Pete Helgren Aug 26 at 19:36
  • OK...I finally found it. In Routes! I had been looking in "Reroute" but it didn't occur to me that there would be another routing method. Thanks for all the help..you gave me a couple of new techniques I can use – Pete Helgren Aug 26 at 19:56
1

The solution was in "Routes" in Settings. I had been looking in "Reroute" but seem to pass over the "Routes" entry...maybe because the names were similar. In Route there was and entry for support/give --> _views/give-new and that was the solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.