-
- 24,544 Posts
I'm pretty sure what you want to do is possible, but I don't understand the question. Can you be more specific?
-
- 2,877 Posts
-
- 315 Posts
Thanks for the replies.
I want to be able to replace placeholders within text that is a php variable rather than a modx chunk. Parsechunk does exactly what I need but it only does it for chunks.
Does that help explain?
BBloke
-
- 24,544 Posts
In Revolution, you can create a chunk and set its content from your PHP variable, then parse it. I'm not sure how you would do that in Evolution. In Revo it looks like this:
$chunk = $modx->newObject('modChunk');
$chunk->setContent($myVariable);
$output = $chunk->process();
-
- 2,877 Posts
REVO is KING!
EVO needs a snippet or placeholder in your template, chunk or resource field: [!php?variable=`[*myTV*]`!]
Are you familiar with the PHx plugin, the IF and getField snippets? Those might help you!
PHx
http://modx.com/extras/package/phx?version=4d556b7cb2b083396d000630
http://rtfm.modx.com/extras/evo/phx
http://wiki.modxcms.com/index.php/PHx
Plugins rule! Examples:
http check event:
OnWebPageInit
if($_SERVER['HTTPS'] == 1) {
$modx->setPlaceholder('http','0');
} elseif ($_SERVER['HTTPS'] == 'on'){
$modx->setPlaceholder('http','0');
} elseif ($_SERVER['SERVER_PORT'] == 443) {
$modx->setPlaceholder('http','0');
} else {
$modx->setPlaceholder('http','1');
}
Then in template:
[+phx:if=`[+http+]`:is=`1`:then=`
<img src="http://.........
`:else=``+]
placeholders check event:
OnParseDocument
$name = "Oggy";
$score = "100";
$hello = <<<END
<p>Hello $name!</p>
<p>Your score is $score</p>
END;
if (!$name){
$modx->setPlaceholder('hello', 'Hello anonymous!');
} else{
$modx->setPlaceholder('hello', $hello);
}
Then in template:
[ed. note: mrhaw last edited this post 10 years, 5 months ago.]
-
- 315 Posts
I think my description is lacking somewhat. Here's another attempt to try and be a little more accurate.
I wish to get some text from a database record which contains placeholders and then change the placeholders with information set in a different part of the a snippet.
It's a lot like how eForm uses the Thank You template but my data is not in a chunk it's in a database record.
I think I found something that may be useful. Would mergePlaceholderContent be the right place to be?
Thanks for all your help so far.
BBloke
BBloke
discuss.answer
-
- 2,877 Posts
$modx->mergePlaceholderContent() discussed in threads:
[php] how to replace placeholders with variables?
http://forums.modx.com/thread/19341/php-how-to-replace-placeholders-with-variables#dis-post-107178
Passing a parameter to @SELECT
http://forums.modx.com/thread/11150/passing-a-parameter-to-select?page=2#dis-post-63866
When I create modules I make use of
$_SESSION vars
I want to use inside functions
$url = $modx->config['site_url'] . 'manager/index.php?a=112&id=' . $_SESSION['moduleID'];
[ed. note: mrhaw last edited this post 10 years, 5 months ago.]
-
- 315 Posts
Thanks mrhaw, I think you've confirmed what it is I need.
Cheers,
BBloke
BBloke