I've written a patch based off of https://github.com/barelon/CgKintBundle to provide Kint functionality inside Twig templates.

I will upload a patch and a couple screenshots momentarily.

Testing steps

  • Enable Kint module
  • Apply patch
  • Add {{ kint() }} to any active Twig template (for example page.html.twig in Bartik)
  • Clear cache (or drush cr)

Visit the homepage and you should see all variables available to the page.html.twig template.

Of course you can pass variable(s) into kint() as well.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

star-szr’s picture

Status: Active » Needs review
FileSize
121 KB
92.86 KB
5.17 KB

Here's the patch and screenshots. Feedback welcome.

Example in page.html.twig:

Example in node.html.twig (displays in context!):

star-szr’s picture

Issue summary: View changes

Grammar fix in issue summary.

star-szr’s picture

FileSize
5.17 KB
526 bytes

Removed trailing whitespace.

moshe weitzman’s picture

Component: devel » kint

This is a big enough piece of code that it is going to need a Maintainer. Would anyone be up for that? It could be the same as the kint module maintainer or someone else.

star-szr’s picture

I might be up for that once I get the code into a bit better shape.

moshe weitzman’s picture

Code looks fine. Would be ideal if someone tested this before commit.

moshe weitzman’s picture

Status: Needs review » Needs work
+        ob_start();
+        \Kint::dump($kint_args);
+        $result = ob_get_clean();

Can be replaced by @\Kint::dump($kint_args);. This did not work with prior version of kint but now that we are on 1.0.0-wip branch it does.

star-szr’s picture

Issue summary: View changes

Hm, making that change seems to make it stop working. I pulled the latest 8.x-1.x of devel, rebased my branch and reinstalled D8, everything worked, then I changed all the \Kint to @\Kint and there is no longer any Kint output. Is there something I'm missing?

star-szr’s picture

FileSize
5.17 KB
1.54 KB

Here's the patch and interdiff for testing/comparison.

corbacho’s picture

@Cottser
The @ operator is used by Kint as a "modifier".

@Kint::dump(); will return the output of the Kint::dump() instead of displaying it on screen.

http://raveren.github.io/kint
So, there is no need to capture the buffer output, just use the value returned.

star-szr’s picture

Status: Needs work » Needs review
FileSize
1.55 KB
1.55 KB

That makes much more sense, thank you @corbacho!

Here is the change with an interdiff from #3.

moshe weitzman’s picture

I think you posted the interdiff twice.

star-szr’s picture

FileSize
5.04 KB

Thanks, here's the actual patch.

The last submitted patch, 11: devel-2218949-11.patch, failed testing.

moshe weitzman’s picture

11: devel-2218949-11.patch queued for re-testing.

moshe weitzman’s picture

How can I get this tested again? I am seeing yellow, not green.

star-szr’s picture

I think the test is postponed because Devel 8.x-1.x-dev HEAD is failing:

https://qa.drupal.org/pifr/test/137984

moshe weitzman’s picture

Status: Needs review » Fixed

Committed. We should document this somewhere.

  • Commit e23fc36 on 8.x-1.x authored by Cottser, committed by moshe weitzman:
    Issue #2218949 by Cottser: Add Kint functionality to Twig templates.
    
Amber Himes Matz’s picture

This is great! I think it might make sense to add documentation for this feature on the Debugging variables in Twig templates (https://drupal.org/node/1906780) or else add a page to that section called "Debugging Twig templates using Devel and Kint."

Would that be a good place for this documentation to live? Other suggestions?

Also, FWIW, I am writing up a blog post on debugging Twig in D8 which will be published on the Drupalize.Me blog next Tuesday and I will include a bit about using kint() in a twig template file.

star-szr’s picture

Assigned: star-szr » Unassigned

@agentolivia - thanks! I can't find a handbook section for Devel (at least it's not linked from the project page) so that seems like a good place to start out with the documentation anyway. It can always be moved + linked later.

joelpittet’s picture

A note for the documentation, twig_debug must be turned on in settings.php, or nothing happens. Should be the first sentence IMO. That caught me when trying it out today:)

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

The last submitted patch, 11: devel-2218949-11.patch, failed testing.

Status: Closed (fixed) » Needs work

The last submitted patch, 13: devel-2218949-8.patch, failed testing.

pcambra’s picture

Status: Needs work » Closed (fixed)
JohnAlbin’s picture

Did a google search for drupal and kint and landed here. Followed Amber's link and noticed the Theming handbook still doesn't have docs about kint(). So I added them. https://www.drupal.org/node/1906780#kint

dump() is hard to use. kint() is easier.

willzyx’s picture

@JohnAlbin thanks for the doc update! note that you can also use {{ devel_dump() }} and {{ devel_message() }} (and their aliases kpr, dpm, dsm) and take advantage of the pluggable dumper system