简体   繁体   English

我如何在Drupal 8中var dump块/节点内容

[英]how can I var dump a block/node content in drupal 8

I am trying to override block theme and rebuild it with html and twig. 我试图覆盖块主题,并用html和twig重建它。

I cant seem to find the variables from the block type or content type and cant find the image url for example. 我似乎无法从块类型或内容类型中找到变量,例如,也无法找到图像网址。

how can i reach it using kint? 如何使用kint达到目标?

The easiest way to dump everything is with 转储所有内容的最简单方法是

{{ dump() }} 

inside your twig template. 在树枝模板中。

I work on fairly large Drupal sites, and I use this to not exhaust the memory from looping through vars. 我在相当大的Drupal网站上工作,并使用它来避免耗尽通过var循环的内存。

<ol>
    {% for key, value in _context  %}
      <li>{{ key }}</li>
    {% endfor %}
</ol>

This will dump everything into a nice ordered list. 这会将所有内容转储到一个有序的列表中。

Hope this helps! 希望这可以帮助!

Also I'm not sure if you're already doing this, but if not -- turn on the twig debug tool, then check out your inspector of choice, and it'll give you suggestions and override data. 另外,我不确定您是否已经在执行此操作,但是如果不这样做,请打开树枝调试工具,然后检查所选的检查器,它会为您提供建议并覆盖数据。

You can do this inside your sites/default/services.yml with 您可以使用以下方法在您的sites / default / services.yml中执行此操作

twig.config:
debug: true 

If you have kint (of Devel module) installed, just use: 如果已安装(Devel模块的)kint,请使用:

{{ kint(_context) }}

Its better than {{ dump() }} , cause kint can manage when the recursion is too long, avoiding memory issues. 它比{{ dump() }}更好,因为当递归时间太长时,kint可以进行管理,从而避免了内存问题。 Second, have a nice way to display the information. 其次,有一种很好的方式来显示信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM