Skip to content

Commit cfe1e2a

Browse files
committed
feature #18754 [DomCrawler] Added argument $default to method Crawler::attr() (alexandre-daubois)
This PR was merged into the 6.4 branch. Discussion ---------- [DomCrawler] Added argument `$default` to method `Crawler::attr()` Fix #18753 Commits ------- a2f361c [DomCrawler] Added argument $default to method Crawler::attr()
2 parents a9adb5b + a2f361c commit cfe1e2a

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

components/dom_crawler.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,18 @@ Access the attribute value of the first node of the current selection::
238238

239239
$class = $crawler->filterXPath('//body/p')->attr('class');
240240

241+
.. tip::
242+
243+
You can define the default value to use if the node or attribute is empty
244+
by using the second argument of the ``attr()`` method::
245+
246+
$class = $crawler->filterXPath('//body/p')->attr('class', 'my-default-class');
247+
248+
.. versionadded:: 6.4
249+
250+
The possibility to specify a default value to the ``attr()`` method
251+
was introduced in Symfony 6.4.
252+
241253
Extract attribute and/or node values from the list of nodes::
242254

243255
$attributes = $crawler

0 commit comments

Comments
 (0)