You need to use $modx->resource->get('pagetitle') in a snippet's code rather than the MODX tag.
http://bobsguides.com/revolution-objects.html
-
- 24,544 Posts
Here's a slightly different way:
<?php
$sentence = $modx->resource->get('pagetitle');
$words = explode(" ", $sentence);
$newSentence = '<strong> ';
$strongClosed = false;
foreach ($words as $word) {
$newSentence .= $word . ' ';
if (! $strongClosed) {
$newSentence .= . '</strong> ';
$strongClosed = true;
}
}
echo $newSentence;
I'm assuming that you don't really need a wordcount and I changed the variable names to conform with the typical PHP convention of having variable names start with a lowercase letter. My apologies if you use a different scheme.
-
- 353 Posts
Thanks guys but unfortunately that bolded all words and not just the first. I need my output to be
The Black Cat
[ed. note: howster last edited this post 9 years, 10 months ago.]
-
- 24,544 Posts
I suspect that the words in your pagetitles are separated by something other than spaces, so the code is treating the whole pagetitle as a word.
Try this:
$sentence = $modx->resource->get('pagetitle');
$words = explode(" ", $sentence);
$output = '<pre>' . print_r($words, true), '</pre>';
return $output;