Blog Sections Open

Passing a Resource Placeholder into a cURL Request

When you build a small integration around cURL , it is common to start with a hard-coded URL and only later replace it with resource data from Evolution CMS. The original question behind this article was simple: how do y

When you build a small integration around cURL, it is common to start with a hard-coded URL and only later replace it with resource data from Evolution CMS. The original question behind this article was simple: how do you put a placeholder like Passing a Resource Placeholder into a cURL Request into a request URL?

The short answer is that placeholders are parsed only in document content and template output. Inside PHP you should read the value directly from the current document or pass it in as a snippet parameter, then build the URL from that value.

Basic Example

$url = $modx->documentObject['pagetitle'];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://sample.ru/search?Search=' . urlencode($url));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);

Why Not Use Passing a Resource Placeholder into a cURL Request Directly?

A tag like Passing a Resource Placeholder into a cURL Request is part of Evolution's parser. PHP code does not automatically expand it. If you concatenate the literal tag into a request, the remote service will receive the string Passing a Resource Placeholder into a cURL Request instead of the actual title.

Better Patterns

  • Use $modx->documentObject['pagetitle'] when you already work inside the current resource context.
  • Pass the value into a snippet explicitly if the request logic lives in a reusable helper.
  • Always wrap dynamic query values with urlencode().

Example as a Reusable Snippet

<?php
$query = isset($query) ? $query : $modx->documentObject['pagetitle'];
$endpoint = 'http://sample.ru/search?Search=' . urlencode($query);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $endpoint);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);

return $result;

This pattern keeps the integration readable and makes it easy to swap the source field later, for example from pagetitle to a TV or a custom search term.

Newer post

Troubleshooting File Uploads in UpdateProfile

A practical checklist for cases where UpdateProfile ignores uploaded files or receives empty POST and FILES arrays in MODX Revolution projects.

Older post

Running Multiple FormIt Forms on One Page Without Cross-Talk

A practical note on FormIt when several forms share one page and start interfering with each other during validation or submission.