-
- 105 Posts
Is there a way to output the actual snippet call, instead of executing it?
If you go here:
http://bobsguides.com/modx-snippet-faq.html
and then go to this question: "Why do I see the actual snippet call on the page instead of my snippet’s output?"
The problem that Bob is addressing is exactly what I want to do.
So instead of the snippet executing, how would I make the actuall call display on the page?
i.e. display:
[[snippet_call]]
I tried htmlspecialchars, htmlentities. The only thing I can think of is creating a function that replaces the [[ ]] with the html equivilants. If there is a function that already does this, it would save me time and increase my php knowledge.
You may or may not want to use the code I write. It's probably all against the syntax rules of php and MODx.
Carpet Cleaning
I use HTML entites, [ and ] for example, instead of [ and ].
-
- 105 Posts
Thank you for helping. I’ll probably use those ideas for creating a function.
I’ve found that I never explain, what I’m trying to do, very well the first time I post a question on a forum.
I’m creating a page, Page-See, that I can use to look at/view a Template (much like when you click edit in MODx, you see the snippet call).
I have another page, Page-Do, that actually uses the Template and needs the snippet to execute.
So I still want the snippet in the Template to execute on when I go to Page-Do that uses the Template, but just display the snippet call when I go to Page-See.
Does that make sense? I may be trying to do something that is impossible.
Maybe I’ll try creating a function to see if this will work.
You may or may not want to use the code I write. It's probably all against the syntax rules of php and MODx.
Carpet Cleaning
-
- 105 Posts
So far I got this to work.
After apply htmlspecialchars().
I sent the Template to this function.
<?php
function exchange_mod_chars($var_h)
{
// [ = [
// ] = ]
// { = {
// } = }
$var_h = str_replace( '[', '[', $var_h);
$var_h = str_replace( ']', ']', $var_h);
$var_h = str_replace( '{', '{', $var_h);
$var_h = str_replace( '}', '}', $var_h);
return $var_h;
}
?>
If there is a function that php already has that does this, I would still be happy to know about it.
You may or may not want to use the code I write. It's probably all against the syntax rules of php and MODx.
Carpet Cleaning
You could use the indexed array method (example 2) of preg_replace to do it all in one step
http://www.php.net/manual/en/function.preg-replace.php
-
- 105 Posts
Thank you so much.
I think I’m just barely starting to realize the power of both PHP and MODx.
You may or may not want to use the code I write. It's probably all against the syntax rules of php and MODx.
Carpet Cleaning
-
- 24,544 Posts
Bob’s guides has a custom snippet that’s frankly not good enough to share. It also uses the comment method.
There’s an excellent plugin in another thread that I would use if I were starting out now:
http://modxcms.com/forums/index.php/topic,14042.0.html.
I posted a Revo version somewhere, but can’t find it.
I’ve found it very useful to occasionally get a cup of tea and go to the PHP documentation, open up one of the categories (especially String Handling) and just read through it. There are a lot of things there that can save hours of trying to code the same functionality, plus the reader notes are also very instructional.