Nov 21, 2008, 07:04 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
Search via SMF or Google: modx forums all of modxcms.com web
  MODxCMS.com   Forums   Help Login Register  
News:Read what MODx Developers say: MODx Dev. Blogs
Pages: [1]   Go Down
  Print  
Author Topic: [snippet] ShowSnippet. Show the contents of a snippet as html.  (Read 5443 times)
0 Members and 1 Guest are viewing this topic.
steph
Member
**
Posts: 85


WWW
« on: Jan 28, 2006, 01:00 PM »

Hi all.

I've written a snippet which outputs the contents of another snippet as html. I use it on my site to display the snippets I've written or modified. http://mindspill.net/computing/cross-platform-notes/modx.html

Steph

* ShowSnippetMindspillDotNet.php.zip (0.88 KB - downloaded 463 times.)
Logged

garryn
Coding Team
*
Posts: 1,175



WWW
« Reply #1 on: Jan 28, 2006, 01:04 PM »

Nice snippet!  Smiley

That'll save me a bit of time copying and pasting ...

Cheers, Garry
Logged

OpenGeek
MODx Co-Founder
Foundation
*
Posts: 5,007


looking a little more like my avatar again...


WWW
« Reply #2 on: Jan 28, 2006, 03:03 PM »

BTW guys, to do this, there is already a built in API function; no extra snippet required!

Code:
$snippetName= 'MySnippet';
$snippetParams= array('param1'=> 'value1, 'param2'=> 'value2',);
$html= $modx->runSnippet($snippetName, $snippetParams);

Not sure why this is not included in the online API documentation, but I'll get that taken care of this weekend.

Let me know if you have any questions on usage.
Logged

Jason Coward
MODx Co-Founder
xPDO Founder
Principal @ Collabpad
work productively.
work intelligently.
work together.
If you think of yourselves as helpless and ineffectual, it is certain that you will create a despotic government to be your master. The wise despot, therefore, maintains among his subjects a popular sense that they are helpless and ineffectual.
  — Frank Herbert
Djamoer
Testers
*
Posts: 1,492

No one can limit a man other than the man himself.


WWW
« Reply #3 on: Jan 28, 2006, 11:35 PM »

I thought that this snippet only showing the code in plain text, instead of running them, am I getting this whole discussion right or what?

Sorry, I might not get the whole discussion in here.
Logged

sottwell
Documentation Team
*
Posts: 8,170



WWW
« Reply #4 on: Jan 29, 2006, 02:02 AM »

It doesn't run the snippet, it just outputs the snippet's source code as plain text.
Logged

sottwell.com has moved to a lovely Solaris 10 server!
Log in username guest, password guestuser.
Templates are now becoming available at http://sottwell.com/templates.html
OpenGeek
MODx Co-Founder
Foundation
*
Posts: 5,007


looking a little more like my avatar again...


WWW
« Reply #5 on: Jan 29, 2006, 03:27 AM »

Sorry guys, I didn't realize this when I read it the first time.  Thanks for the clarification.
Logged

Jason Coward
MODx Co-Founder
xPDO Founder
Principal @ Collabpad
work productively.
work intelligently.
work together.
If you think of yourselves as helpless and ineffectual, it is certain that you will create a despotic government to be your master. The wise despot, therefore, maintains among his subjects a popular sense that they are helpless and ineffectual.
  — Frank Herbert
Djamoer
Testers
*
Posts: 1,492

No one can limit a man other than the man himself.


WWW
« Reply #6 on: Jan 29, 2006, 07:55 PM »

Sorry guys, I didn't realize this when I read it the first time.  Thanks for the clarification.

lol, Jason, I think you just did way too much programming lately. Time to take a break for a while Wink
Logged

Mark
Coding Team
*
Posts: 3,247


Ditto Developer


WWW
« Reply #7 on: Jan 29, 2006, 07:56 PM »

I believe there is an Etomite snippet that does this with syntax highlighting, etc.
Logged

steph
Member
**
Posts: 85


WWW
« Reply #8 on: Jan 30, 2006, 03:25 AM »

Hi.

I've found the etomite snippet. It's called DisplayCode and it's on the second page of their miscelaneous snippets... http://www.etomite.org/browsesnippets.html?int_page=2&lst_category=10 (I didn't link directly to the snippet because I don't think it's allowed). Ok, that's not allowed either!

I tried it but got a lot of odd characters that couldn't be interpreted by the browser and "Warning: Unexpected character in input" warning messages. Also, some characters, like < and >, aren't encoded into html so the doc is still being interpreted as php (hence the warning messages).

Test page here: http://mindspill.net/computing/cross-platform-notes/displaycode-snippet-test.html

If anyone gets it working (or if I'm using it in the wrong way) please let me know.

Steph
« Last Edit: Jan 30, 2006, 03:33 AM by steph » Logged

stempy
Jr. Member
*
Posts: 48


« Reply #9 on: Mar 03, 2006, 05:18 AM »

Updated this slightly to use php's syntax colour highlighting.

Added optional &noHighlight parameter to just display normal html output.

* ShowSnippetCode.snippet.txt (1.74 KB - downloaded 484 times.)
« Last Edit: Mar 03, 2006, 05:29 AM by stempy » Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP

Copyright © 2005-2008 MODxCMS, All rights reserved. Contact Us
Styles by ziworks.com

Powered by SMF 1.1.4 | SMF © 2005, Simple Machines LLC

Valid XHTML 1.0! Valid CSS!