Page 1 of 1

$CONTENT, $ENTRIES, $ARCHIVES

Posted: Sat Sep 02, 2006 10:47 pm
by carl_galloway
Can anyone tell me how these variables $CONTENT, $ENTRIES, $ARCHIVES are created?

Can I create new uppercase variables that link to my own smarty files?

Re: $CONTENT, $ENTRIES, $ARCHIVES

Posted: Sun Sep 03, 2006 11:48 am
by biancospino
carl_galloway wrote:Can anyone tell me how these variables $CONTENT, $ENTRIES, $ARCHIVES are created?
Checking Serendipity code it seems these Smarty variables are fetched through the relative template files (*.tpl) and then assigned again to Smarty.
You can see them at:
- genpage.inc.php, line 101 for CONTENT
- functions_entries.inc.php, line 854 and 1440 for $ENTRIES, $ARCHIVES

Garvin...your code is great and well written, thank you for sharing... "German do it better" :)
carl_galloway wrote: Can I create new uppercase variables that link to my own smarty files?
I don't know :(

ciao

Re: $CONTENT, $ENTRIES, $ARCHIVES

Posted: Mon Sep 04, 2006 10:13 am
by garvinhicking
Hi!

Uppercase variable names in our case, like binacospino pointed out, indicate that code is fetched from other files.

This is done through the use of serendipity_smarty_fetch(). It is used in our PHP code and tells that $CONTENT is the content of the file 'content.tpl'.

If you just place $MYFILE in your template file, then it will print an empty variable because smarty does not know where it should get the contents from. This means that you would need to write PHP code (through the use of a plugin or config.inc.php) that uses the assign() method or the serendipity_smarty_fetch() to associate a file with a variable.

If you turn smarty security off, you could use:

Code: Select all

{'MYVAR'|serendipity_smarty_fetch:'myfile.tpl'}
{$MYVAR}
to achieve fetching a file like that. Having smarty security turned on, you would first need to wrap that function:

Code: Select all

$serendipity['smarty']->register_modifier('serendipity_smarty_fetch', 'serendipity_smarty_fetch');
to use the same code like above. You could also create a wrapper smarty function, but that would be more trouble as different function arguments would be required.

HTH,
Garvin

Posted: Mon Sep 04, 2006 10:16 am
by carl_galloway
Ok, that answers my question nicely, so basically those variables just call the template file with the samer name, that means they aren't special at all. There is no additional parsing happening. So if I want to create my own smarty files I should just use the {include file} directive. Cool.