1

How to escape into and use raw php in Latte in Nette , eg can be used for debugging and other non standard, not best practices cases , logging and what not as its not standard, and rather in edge or debugging cases perhaps obviously

FantomX1
  • 1,577
  • 2
  • 15
  • 23

2 Answers2

1

For debugging purposes, there should be enought build-in {dump} or {dump $var} macro.

https://latte.nette.org/en/tags#toc-dump

0

In .latte (@layout.latte) files, one might use this syntax, a {php} or alias {do} latte tag to execute raw code inside it, like

{do Tracy\Debugger::barDump(get_defined_vars()); }

or any standard php like

{php var_dump([1,2,3,4]); echo "text"; }

https://latte.nette.org/en/tags#toc-do

FantomX1
  • 1,577
  • 2
  • 15
  • 23
  • Not supposed to end in a semicolon or the compiler will error when using the php or do tags. Also needs to be a single statement. Also cannot use echo or print. But you can use printf. – Kevin Y Jun 17 '22 at 23:43
  • @KevinY have not you mistaken this question for the other framework? I have extensive knowledge in various programming languages and I rarely or if ever post something what was not tested. I directly dont see a problem with it, and you dont seem to have a single SO interaction on Nette framework but you deal a lot with other, laravel etc. due to that and also asking since you have a English sounding name, and Nette framework is not yet much known abroad outside its country of origin. – FantomX1 Jun 22 '22 at 18:44
  • @KevinY Also sincerely such reasoning doesn't make much sense to me. Its called escaping the template engine for a reason you expect literally, its directly my main goal , such standard language constructs and mechanism there, or if you can elaborate a bit more, I cant quite normally imagine a programming language, let alone php, without semicolons or multiple statements. In escaping to the programming language to begin with. – FantomX1 Jun 22 '22 at 18:50
  • Sorry, my comment is specific to latte v3 which I just worked on: https://stackoverflow.com/questions/72654633/how-to-write-an-unescaped-javascript-filter-in-php-latte-v3#comment128338134_72654633 Sometimes I move too fast on SO and think I can knock out two birds with one stone. Didn't realize v3 was only 6 months ago. – Kevin Y Jun 22 '22 at 20:37
  • If you do decide to upgrade later: https://latte.nette.org/en/cookbook/migration-from-latte2#toc-syntax-changes `The {do ...} or {php ...} tag can only contain expressions` – Kevin Y Jun 22 '22 at 20:44