Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 50c0823

Browse filesBrowse files
committed
minor #10898 Documented the default values of text() and html() (javiereguiluz)
This PR was merged into the master branch. Discussion ---------- Documented the default values of text() and html() Documents symfony/symfony#28581 See also https://symfony.com/blog/new-in-symfony-4-3-domcrawler-improvements Commits ------- 851956d Documented the default values of text() and html()
2 parents ef64a7e + 851956d commit 50c0823
Copy full SHA for 50c0823

File tree

1 file changed

+16
-0
lines changed
Filter options

1 file changed

+16
-0
lines changed

‎components/dom_crawler.rst

Copy file name to clipboardExpand all lines: components/dom_crawler.rst
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,16 @@ Access the node name (HTML tag name) of the first node of the current selection
201201

202202
Access the value of the first node of the current selection::
203203

204+
// if the node does not exist, calling to text() will result in an exception
204205
$message = $crawler->filterXPath('//body/p')->text();
205206

207+
// avoid the exception passing an argument that text() returns when node does not exist
208+
$message = $crawler->filterXPath('//body/p')->text('Default text content');
209+
210+
.. versionadded:: 4.3
211+
212+
The default argument of ``text()`` was introduced in Symfony 4.3.
213+
206214
Access the attribute value of the first node of the current selection::
207215

208216
$class = $crawler->filterXPath('//body/p')->attr('class');
@@ -298,8 +306,16 @@ and :phpclass:`DOMNode` objects::
298306
Or you can get the HTML of the first node using
299307
:method:`Symfony\\Component\\DomCrawler\\Crawler::html`::
300308

309+
// if the node does not exist, calling to html() will result in an exception
301310
$html = $crawler->html();
302311

312+
// avoid the exception passing an argument that html() returns when node does not exist
313+
$html = $crawler->html('Default <strong>HTML</strong> content');
314+
315+
.. versionadded:: 4.3
316+
317+
The default argument of ``html()`` was introduced in Symfony 4.3.
318+
303319
Expression Evaluation
304320
~~~~~~~~~~~~~~~~~~~~~
305321

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.