Page 1 of 1

Constant values through the s9y code?

Posted: Sun Sep 24, 2006 3:27 am
by rodney
Hi all,

I'm new to Serendipity and am familiarizing myself with the codebase. First, let me say congratulations on a fine Web application - keep up the good work!

Just wondering if there is a consistent way to change the value of constants rather than simply replacing them where they appear. For example, if you want change a string of text from "the" to "and" you could go into the template and edit the {$CONST.XXX} with what you want to show. Is there a central repository for all these with the default distribution?

I have searched around the forums/Internet with no luck yet.

Best regards
Rodney

Posted: Sun Sep 24, 2006 5:59 am
by Ctwizzy
Hey Rod, not sure exactly what your talking about if you could give a code sample it might help.

Im no expert but ive done some tinkering around in the code and will help if possible.

Constant values through the s9y code?

Posted: Sun Sep 24, 2006 7:50 am
by rodney
Here's an example from comments.tpl...

Code: Select all

<div class="serendipity_center">{$CONST.NO_COMMENTS}</div>
$CONST.NO_COMMENTS ???

and

Code: Select all

{if $comment.email}
                <a href="mailto:{$comment.email}">{$comment.author|@default:$CONST.ANONYMOUS}</a>
            {else}
                {$comment.author|@default:$CONST.ANONYMOUS}
            {/if}
$CONST.ANONYMOUS ???

I understand they can be replaced with specified content of your choosing but I'm wondering where they come from in the first place. Is there a central repository of constant values?

Best regards,
Rodney

Posted: Sun Sep 24, 2006 8:16 am
by Ctwizzy
Ah Ok,

Ok hopefully this answers your question.

tpl are smarty files, they just relay information at run time from the php files. They are like the clock face behind the gears.

The info your looking for is in the application itself. Gavin developed S9Y with templating in mind to change S9Y your looking to tinker with the backend.

In order to find what your looking for your gona need a multi-file finding app. I dont know what your use for editing, I use Editplus but basically search ALL files in s9y for the const.

I dont know if there are debuggers with php or not, that might also help you.

Posted: Sun Sep 24, 2006 8:59 am
by rodney
Thanks for that reply.

Hmmm... having to manually search through all the s9y files seems like a strange way to locate const values...

I mean, if that is the case the values themselves may as well be statically coded into the template... or am I missing something about these $CONST things that provides a more overall meaning?

Best regards,

Rodney

Re: Constant values through the s9y code?

Posted: Sun Sep 24, 2006 4:37 pm
by stm999999999
rodney wrote: $CONST.ANONYMOUS ???

I understand they can be replaced with specified content of your choosing but I'm wondering where they come from in the first place. Is there a central repository of constant values?
these are (in most cases?) language constants.

They are defined in lang/serendipity_lang_xx.inc.php

e.g.

Code: Select all

@define('ANONYMOUS', 'Anonymous');
You can change it in the inc.php but there is a problem: updating s9y will restore the old values :-(

So, do this:

Add your own language definitions in your choosen template directory:

e.g. lang_en.inc.php

normaly this file is only for definitions especial for constants only used in this very template and not for definitions which occurs in the normal lang-file (the template-lang-file cannot override the normal definitions).

But there is a way to make your own language definitions. I is not experimental, it works well, but it is not promoted, yet:

in serendipity_config_local.inc.php

add at the end:

Code: Select all

	// End of Serendipity configuration file
	// You can place your own special variables after here:

	$serendipity['useTemplateLanguage'] = true;


?>
from now on, your definition in the template-lang-file have higher priority

Posted: Tue Oct 31, 2006 2:27 am
by mima
Hi,

can I also define _new_ words in the template lang_xx.inc.php file?

I'm asking, because if I write this:

Code: Select all

<li>{$CONST.CONTACT}</li>
<li>{$CONST.DONE}</li>
the predefined DONE is evaluated well in all languages, but CONTACT is just recognized in english.

my lang files are like this:

Code: Select all

<?php
@define('START', 'Start');
@define('FORUM', 'Forum');
@define('SCHEDULE', 'Kalender');
@define('GALLERY', 'Gallerie');
@define('CONTACT', 'Kontakt');
@define('IMPRINT', 'Impressum');
?>
and I ripped the config.inc from the kubrick theme:

Code: Select all

<?php # $Id: config.inc.php 108 2005-05-19 08:40:00Z garvinhicking $

$probelang = dirname(__FILE__) . '/lang_' . $serendipity['lang'] . '.inc.php';
if (file_exists($probelang)) {
    include $probelang;
} else {
    include dirname(__FILE__) . '/lang_en.inc.php';
}

?>
I added this line to the config.local.inc.php

Code: Select all

$serendipity['useTemplateLanguage'] = true;
I'm terribly sorry asking this, but I searched overall the forum and docs but haven't found any relevant answer; and checked the syntax a hundret times :?
I also tried to add the defines to the lang/serendipity_lang_xx.inc.php files, but they weren't recognized there, too... hummm

I'd be really thankful for a small hint!
Thanks alot,
Michael

Posted: Tue Oct 31, 2006 10:11 am
by garvinhicking
Hi mima!

Could you show us your complete *.php files in your template directory? My guess is that not all files contain the constant declaration? And maybe you are missing the "UTF-8" subdirectory PHP files to add your constants to?

Best regards,
Garvin

Posted: Tue Oct 31, 2006 11:55 am
by mima
garvinhicking wrote:Hi mima!
And maybe you are missing the "UTF-8" subdirectory PHP files to add your constants to?
argh :oops:
as always when I'm posting to forums, the answer is easy and a bit embarrassing to me :oops:

Thank you for that wonderful peace of software!
(I am so sad, that my private blog runs with WP; since I installed s9y for our university class homepage, I am missing all those cool s9y features... :lol: )

Posted: Tue Oct 31, 2006 2:40 pm
by garvinhicking
Hi!

Great we could solve this portion of your problem(s). :)

Nice to hear you enjoy serendipity! Spread the word :)

Best regards,
Garvin