[英]How display all methods from an object from twig?
我尝试使用 twig dump 获取所有方法的列表。
<div>
{% if listPosts is defined %}
{{ dump(listPosts) }}
{% endif %}
</div>
但我只得到这个列表:
SlidingPagination {#575 ▼
-route: "bissap_forum_topic"
-params: array:2 [▶]
-pageRange: 2
-template: "KnpPaginatorBundle:Pagination:sliding_bissap.html.twig"
-sortableTemplate: "KnpPaginatorBundle:Pagination:sortable_link.html.twig"
-filtrationTemplate: "KnpPaginatorBundle:Pagination:filtration.html.twig"
#currentPageNumber: "1"
#numItemsPerPage: 8
#items: array:8 [▶]
#totalCount: 11
#paginatorOptions: array:6 [▶]
#customParameters: []
}
如何在树枝中显示对象的所有方法名称?
你需要的是一个树枝过滤器。 通过这种方式,您可以在 php 中实现例如list_functions
过滤器,并从树枝中使用它,例如:
{{ listPosts | list_functions }}
您需要在 php 中实现逻辑,因为您不能直接在 twig 中使用 php。 使用get_class_methode应该很容易。 通过这种方式,您可以获得所有函数的列表,但您必须决定要调用哪个函数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.