GetSimple Support Forum

Full Version: Displaying HTML code on pages
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I want to be able to display code such as:

Code:
<?php
/* Credit to ccagle8 for the original function; edited by Angryboy */
function get_author_username($blogusername) {
  $file = GSDATAPAGESPATH . $blogusername .'.xml';
    if (file_exists($file)) {
    $p = getXML($file);
    $authoruser = $p->authoruser;
    echo $authoruser; }
    }
?>

In this form for tutorials about GetSimple. But even when I encode the < and > entities, they are still executed, making the code unable to be viewed and breaking the web page. This even goes for showing other bracketed codes:

Code:
(% stuff in here %)

I've had to insert spaces between the < and > signs, but I've seen other sites display their code just fine. Is there something I'm doing wrong, or could this be a server problem?

Thanks to whoever provides a solution!
Angryboy Wrote:I want to be able to display code such as:

Code:
<?php
function get_author_username($blogusername) {
...
?>

This works just fine for me in the page!?

Angryboy Wrote:This even goes for showing other bracketed codes:
Code:
(% stuff in here %)

This is a real problem.
There is a workaround if you have htmlentities in ckeditor switched on (which is the default at least for GS 3.0): before saving the page go to source view and replace all % by %, then save immediately without switching to WYSIWYG mode.
mvlcek Wrote:There is a workaround if you have htmlentities in ckeditor switched on (which is the default at least for GS 3.0): before saving the page go to source view and replace all % by %, then save immediately without switching to WYSIWYG mode.

i had a similiar problem last year and solved using a component for that code snippet
mvlcek Wrote:
Angryboy Wrote:I want to be able to display code such as:

Code:
<?php
function get_author_username($blogusername) {
...
?>

This works just fine for me in the page!?

Angryboy Wrote:This even goes for showing other bracketed codes:
Code:
(% stuff in here %)

This is a real problem.
There is a workaround if you have htmlentities in ckeditor switched on (which is the default at least for GS 3.0): before saving the page go to source view and replace all % by %, then save immediately without switching to WYSIWYG mode.
I know it works fine for you, which is why I am a little jealous to be frank XD As you can see on the page link I gave, the code is still being processed as though the < and > were actual markers instead of entities. The HTML I view when I look at the CKEditor source on the page content tells me that they are entities, yet the page still processes them as non-entities. What is more annoying is that the code is displaying just fine from within the CKEditor!

@marcco: thanks for the contribution. Because I have a lot of code snippets in my tutorials however, it would be a bit cumbersome to produce a component for every code snippet I produced XD
Angryboy Wrote:I know it works fine for you, which is why I am a little jealous to be frank XD As you can see on the page link I gave, the code is still being processed as though the < and > were actual markers instead of entities. The HTML I view when I look at the CKEditor source on the page content tells me that they are entities, yet the page still processes them as non-entities. What is more annoying is that the code is displaying just fine from within the CKEditor!

How do you format the code in CKEditor?
For me it only works, if I use the "Preformatted" entry in the standard "Format" combo box.
This way it's all within a <pre> (without <code> as for you).
Angryboy Wrote:I want to be able to display code such as:

Code:
<?php
/* Credit to ccagle8 for the original function; edited by Angryboy */
function get_author_username($blogusername) { ... }
?>

In this form for tutorials about GetSimple. But even when I encode the < and > entities, they are still executed, making the code unable to be viewed and breaking the web page. This even goes for showing other bracketed codes:

Code:
(% stuff in here %)

I've had to insert spaces between the < and > signs, but I've seen other sites display their code just fine. Is there something I'm doing wrong, or could this be a server problem?

Thanks to whoever provides a solution!

Have you tried pasting your code straight into the WYSIWYG editor?
Works for me!
http://eatons.net/tutorials/innnovationoutline/
eatons Wrote:Have you tried pasting your code straight into the WYSIWYG editor?
Works for me!
http://eatons.net/tutorials/innnovationoutline/
I've tried this now that you've asked. My source code in the WYSIWYG editor is this:

Code:
<pre>
    &lt;?php

    /* Credit to ccagle8 for the original function; edited by Angryboy */

    function get_author_username($blogusername) { ... }

    ?&gt;</pre>

When viewed on the actual page, the source code becomes this:

Code:
<pre>    <!--?php

    /* Credit to ccagle8 for the original function; edited by Angryboy */

    function get_author_username($blogusername) { ... }

    ?--></pre>

Making it unviewable. Thanks for offering some help to me regardless :-)
Angryboy Wrote:
eatons Wrote:Have you tried pasting your code straight into the WYSIWYG editor?
Works for me!
http://eatons.net/tutorials/innnovationoutline/
I've tried this now that you've asked. My source code in the WYSIWYG editor is this:

Code:
<pre>
    &lt;?php
    ...

    ?&gt;</pre>

When viewed on the actual page, the source code becomes this:

Code:
<pre>    <!--?php

    ...

    ?--></pre>

Making it unviewable. Thanks for offering some help to me regardless :-)

I set up a test page at: http://eatons.net/tutorials/test/
Is either of these what you're looking for?
eatons Wrote:
Angryboy Wrote:
eatons Wrote:Have you tried pasting your code straight into the WYSIWYG editor?
Works for me!
http://eatons.net/tutorials/innnovationoutline/
I've tried this now that you've asked. My source code in the WYSIWYG editor is this:

Code:
<pre>
    &lt;?php
    ...

    ?&gt;</pre>

When viewed on the actual page, the source code becomes this:

Code:
<pre>    <!--?php

    ...

    ?--></pre>

Making it unviewable. Thanks for offering some help to me regardless :-)

I set up a test page at: http://eatons.net/tutorials/test/
Is either of these what you're looking for?
The top one is Smile

I think I've found the problem, and it might be a bug with the way that Special Pages processes page content. I copied the HTML code from your page onto a test normal page and it displays fine:

http://spritingonawhim.net.tc/testpage/

But that very same content on a special page:

http://spritingonawhim.net.tc/testpage2/

And it processes the <?php as thought it were an actual command. The use of
<?php get_page_content(); ?>
in a Special Page's template doesn't output the content in the same way that it does for normal pages.

Thanks for your contribution, eatons!

--------------------

Found my solution!

Code:
<?php get_special_field('content', $default='', $isHTML=false); ?>

Instead of the usual get_page_content, because the default for that is to encode the characters < and > for special fields. Sorry for the trouble caused people!

Note for mvleck: you may want to make that clear on the Special Pages information you've got so that others don't make my silly mistake either!