Page 1 of 1
Inserting Code Into an Entry
Posted: Fri Sep 15, 2006 8:18 am
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!
Re: Inserting Code Into an Entry
Posted: Fri Sep 15, 2006 9:23 am
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
Posted: Fri Sep 15, 2006 5:44 pm
by Ctwizzy
Once again Garvin thanks.
Posted: Fri Sep 15, 2006 7:07 pm
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
Posted: Fri Sep 15, 2006 7:46 pm
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.
Posted: Fri Sep 15, 2006 7:58 pm
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
Posted: Fri Sep 15, 2006 8:20 pm
by carl_galloway
In the example you've quoted, you would also need to replace all
with
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.
Posted: Sat Sep 16, 2006 2:50 am
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.
Posted: Sat Sep 16, 2006 8:01 am
by carl_galloway
Ah yes the simple things... forget them and they completely stuff up your whole day.