Inserting Code Into an Entry

Random stuff about serendipity. Discussion, Questions, Paraphernalia.
Post Reply
Ctwizzy
Regular
Posts: 19
Joined: Thu Sep 07, 2006 10:41 pm

Inserting Code Into an Entry

Post by Ctwizzy »

Ok so I am writing code tutorials on mysite pretty much documenting things I do and learn, but problem is when I try to insert code it wont let me. It prints the actual code.

Why is there no option in the entry field? Is there anyway besides doing a <text-area> which I dont like doing as then I have to hard code the width and height etc...

Thanks!
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Inserting Code Into an Entry

Post by garvinhicking »

Hi!

You should be able to use <code></code> HTML tags.

Or you can install the BBCode plugin and use the \

Code: Select all

 tag.

Or you can install the GeSHI markup plugin which deals with syntax highlighting.

Best regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Ctwizzy
Regular
Posts: 19
Joined: Thu Sep 07, 2006 10:41 pm

Post by Ctwizzy »

Once again Garvin thanks.
Ctwizzy
Regular
Posts: 19
Joined: Thu Sep 07, 2006 10:41 pm

Post by Ctwizzy »

Alright I installed the Geshi plugin (unrared and moved the files to /plugins/ and then installed in event.

So in my entry I type
[geshi]
<?php
function my_menu($params, &$smarty) {
$out = '<ul class="sitesections">';
$items = array("Home" => "index.php", "Filler" => "index.php", "Filler" => "index.php");
foreach($items AS $item => $link) {
$out .= '<li><a href="' . $link . '">' . $item . '</a>';
}
return $out;
}
$serendipity['smarty']->register_function('my_menu', 'my_menu');
?>
[/geshi]

and nothing.

if I put [geshi lang=php] it works, but [geshi lang=php ln=1] wont. It seems extremely tempermental. It also hates quotes and some other nonsense.

I am looking for documentation on the proper syntax of using geshi I even visited the authors website and found no such documentation. If someone could point me in the right direction id be in your debt. Thanks!

Thanks
carl_galloway
Regular
Posts: 1331
Joined: Sun Dec 04, 2005 5:43 pm
Location: Andalucia, Spain
Contact:

Post by carl_galloway »

If you're going to all that much effort to insert a code snippet, why don't you just use the regular editor without geshi and simply place a manual <code></code> around your snippet. Then if you're not happy with the way code snippets are displayed, simply edit or add code {} to your template's stylesheet.

This approach has the advantage of one less plugin installed (every additional plugin affects performance), and means that if you ever need to copy and paste your entry to another site the html is already there and doesn't need to be converted from geshi.
Ctwizzy
Regular
Posts: 19
Joined: Thu Sep 07, 2006 10:41 pm

Post by Ctwizzy »

Thats the problem carl, I tried it that way it doesnt work.

using
[/code/]
<?php
function my_menu($params, &$smarty) {
$out = '<ul class="sitesections">';
$items = array("Home" => "index.php", "Filler" => "index.php", "Filler" => "index.php");
foreach($items AS $item => $link) {
$out .= '<li><a href="' . $link . '">' . $item . '</a>';
}
return $out;
}
$serendipity['smarty']->register_function('my_menu', 'my_menu');
?>
[/code/]

and
<code>
<?php
function my_menu($params, &$smarty) {
$out = '<ul class="sitesections">';
$items = array("Home" => "index.php", "Filler" => "index.php", "Filler" => "index.php");
foreach($items AS $item => $link) {
$out .= '<li><a href="' . $link . '">' . $item . '</a>';
}
return $out;
}
$serendipity['smarty']->register_function('my_menu', 'my_menu');
?>
</code>

The display isnt outputting all the text between the two tags its thinking its real code, I dont want it embeded as code in the page I want it as plain text.

Thanks
carl_galloway
Regular
Posts: 1331
Joined: Sun Dec 04, 2005 5:43 pm
Location: Andalucia, Spain
Contact:

Post by carl_galloway »

In the example you've quoted, you would also need to replace all

Code: Select all

<>
with

Code: Select all

< >

respectively. Then the code would render correctly in your browser. I find a simple find/replace in my text editor does the job very well.
Ctwizzy
Regular
Posts: 19
Joined: Thu Sep 07, 2006 10:41 pm

Post by Ctwizzy »

Thanks carl, its the simple things you forget lol.

I can see this way getting tedious though, so Im going to look for the bbcode plugin, I cant see it taking up too much memory.
carl_galloway
Regular
Posts: 1331
Joined: Sun Dec 04, 2005 5:43 pm
Location: Andalucia, Spain
Contact:

Post by carl_galloway »

Ah yes the simple things... forget them and they completely stuff up your whole day.
Post Reply