Could someone point me in the direction of a post, or wiki article that explains how to go about including a block of “code” within a template so that is actually displays as code?
Thanks
This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.
The active forums are here.
September 18, 2007 3:13pm
Subscribe [2]#1 / Sep 18, 2007 3:13pm
Could someone point me in the direction of a post, or wiki article that explains how to go about including a block of “code” within a template so that is actually displays as code?
Thanks
#2 / Sep 18, 2007 3:33pm
In a template or a weblog entry? In a weblog entry, just use the “code” tag. For inside a template… what kind of code? EE code, php code, what? If it’s php, just turn off php parsing for that template and you are good to go. If you have to have php on, you can use a heredoc statement to output it (in fact, that’s what the forum templates do).
I’d likely do that, in fact. You want to do EE code without it being rendered? You could use a php heredoc statement for it. Like so:
.... //previous template code here
So then we see how to use EE tags like this:
<?php $str = <<<EOD
{exp:weblog:entries category="test"}
{title}
More stuff here
{body}
{/exp:weblog:entries}
EOD;
echo $str;
?>
As we can see, the tag….This should allow you to put whatever you want inside the heredoc syntax, just copied and pasted from whatever you want put in—no need to worry about concenating strings, etc.
Hope that helps!
#3 / Sep 18, 2007 4:09pm
Hey, thanks for responding. Actually, I’m putting together a tip sheet for users of one of the projects I’m working on to instruct them on how to properly embed video media so that the page containing it still validates.
I’m simply doing html; e.g:
<object data="http://www.youtube.com/v/knFykmLljos"
type="application/x-shockwave-flash"
height="350" width="425">
<a href="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash">Install Flash Player to view content</a>
</object>
I found the “Pretty PHP plugin” which is perfect for what I need, but the trouble with it is that any block of code wrapped between the tags is rendered with <?php ?> tags. Not exactly what I want.
I did try what you had provided but it actually renders the video.
#4 / Sep 18, 2007 4:12pm
Ah, okay. Yes, that code WOULD be rendered, as my solution just outputs that code to skip EE’s parser—and EE isn’t parsing anything in that code, so the browser just renders it.
Try maybe using the <pre> or <code> tags, then. They may do it.
#5 / Sep 18, 2007 4:32pm
Yeah, I was actually using pre-tags (they don’t work), and just tried <code> but both render the html.
❓
#6 / Sep 18, 2007 4:42pm
You have to convert the tags to entities, unfortunately. Take the code you are trying to put in and run it through an entity converter.
Here’s that code up above converted:
<object data="http://www.youtube.com/v/knFykmLljos" type="application/x-shockwave-flash" height="350" width="425"> <param name="movie" value="http://www.youtube.com/v/knFykmLljos" /> <param name="FlashVars" value="playerMode=embedded" /> <p> <a href="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod _Version=ShockwaveFlash">Install Flash Player to view content</a> </p> </object>
You’ll have to quote my post to actually SEE the code, because the browser is successfully translating it. However, it shows it works.
And here is, among many others, a page to convert it to entities.
Hope that helps! Oh, you could change the pre tag to a code tag easily enough.
#7 / Sep 18, 2007 6:39pm
Wow…very cool tool. It would take a forever to manually convert each character.
Thanks!