From a2f361ce8c1fc96549646b9c3712ecc5b7301c86 Mon Sep 17 00:00:00 2001 From: Alexandre Daubois Date: Wed, 16 Aug 2023 13:10:53 +0200 Subject: [PATCH] [DomCrawler] Added argument $default to method Crawler::attr() --- components/dom_crawler.rst | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/components/dom_crawler.rst b/components/dom_crawler.rst index 713073e30eb..4440a35f0ea 100644 --- a/components/dom_crawler.rst +++ b/components/dom_crawler.rst @@ -238,6 +238,18 @@ Access the attribute value of the first node of the current selection:: $class = $crawler->filterXPath('//body/p')->attr('class'); +.. tip:: + + You can define the default value to use if the node or attribute is empty + by using the second argument of the ``attr()`` method:: + + $class = $crawler->filterXPath('//body/p')->attr('class', 'my-default-class'); + + .. versionadded:: 6.4 + + The possibility to specify a default value to the ``attr()`` method + was introduced in Symfony 6.4. + Extract attribute and/or node values from the list of nodes:: $attributes = $crawler