Handbuch für Serendipity bestellen
Das offizielle, umfassende Serendipity-Handbuch für Einsteiger und Profis ist nun im Handel und kann online bei Amazon oder OpenSourcePress, oder auch bei jedem Buchhändler, bestellt werden!
|
Forum-Information
Before posting about errors, make sure that the answer cannot already be found
in our FAQ or by searching this forum!
Posting is restricted to registered users ( registering is free and simple!) due to recent spam attacks. When having trouble with this board, contact garvin(-at)s9y(-dot)org.
|
Random stuff about serendipity. Discussion, Questions, Paraphernalia.
-
eggy
-
by eggy » Mon Nov 21, 2005 8:47 am
hey fellas-
quick noob question- i have a decent grasp of php, but need to get smart on how smarty works... i've checked out the article at:
http://www.s9y.org/78.html. but am having trouble getting things to work when i try to use custom php funtioncs.
just want to make sure i have the basics correct:
1- in the config.inc.php file for my theme, i can define php functions as i normally do.
2- in the config.inc.php, call $serendipity['smarty']->register_function....
3- install smarty parsing plugin
4- then i can use smarty calls- for example, in the example given in 78.html, i should be able to just call "{$my_custom_function}" from my entry, right?
if not, what am i missing? thanks!
-

garvinhicking
- Core Developer
-
- Posts: 26675
- Joined: Tue Sep 16, 2003 9:45 pm
- Location: Cologne, Germany
-
Re: noobie smarty / custom php question...
by garvinhicking » Mon Nov 21, 2005 1:19 pm
Yes, you can run functions like these. But you call your functions with {myfunction} only, not {$myfunction}. And your PHP function declaration needs to be alerted a bit, since it uses a $params and $smarty variable.
But of course you can use a proxy function to access your real function like this:
- Code: Select all
config.inc.php <?php function myFunction($do, $this, $here) { }
function smarty_myFunction($params, &$smarty) { return myFucntion($params['do'], $params['this'], $params['here']); }
$serendipity['smarty']->register_function('myFunction', 'smarty_myFunction'); ?>
Smarty template: {myFunction do=1 this=1 here=1}
Regards,
Garvin
-
eggy
-
by eggy » Tue Nov 22, 2005 7:13 am
thanks garvin-
got the php stuff working exactly as i want. now, i need to get me some javascript working. =D
it appears that writing your own javascript functions will not work in entries(but basic javascript does) - is this correct? any suggested workarounds?
-

garvinhicking
- Core Developer
-
- Posts: 26675
- Joined: Tue Sep 16, 2003 9:45 pm
- Location: Cologne, Germany
-
by garvinhicking » Tue Nov 22, 2005 11:34 am
You can write javascript in your entries! But if you've enabled the NL2BR Markup plugin, that interfers with writing code, so that you would need to write your javascript all in one line!
Also remember that Smarty needs to escape { and } with {ldelim} and {rdelim}!
Regards,
Garvin
-
eggy
-
by eggy » Tue Nov 22, 2005 9:29 pm
well... i can write javascript, but if i try to include a function in my javascript, it seems to bomb- even if i include just a empty function.
-
eggy
-
by eggy » Tue Nov 22, 2005 9:32 pm
oops, hit submit by accident...
as an example, if within the javascript i just add:
function loadXMLDoc(url) {
}
I get the error:
Fatal error: Smarty error: [in smartymarkupplugin:1655783225 line 5]: syntax error: unrecognized tag: (Smarty_Compiler.class.php, line 436) in /home/content/e/d/s/edscholl/html/blog/bundled-libs/Smarty/libs/Smarty.class.php on line 1088
-

garvinhicking
- Core Developer
-
- Posts: 26675
- Joined: Tue Sep 16, 2003 9:45 pm
- Location: Cologne, Germany
-
by garvinhicking » Tue Nov 22, 2005 9:53 pm
Eggy, please read what I posted.
Regards,
Garvin
-
eggy
-
by eggy » Tue Nov 22, 2005 11:10 pm
sorry garvin, had a little bit of a brain fart. i read your comments about escaping the delimters and it didn't even register as being applicable. 
-
eggy
-
by eggy » Mon Dec 05, 2005 3:31 am
alright... more questions...
1: using the example provided, if I simply call
{myFunction do=1 this=2 here=3}
it seems to work in that my page prints out what's expected (i'm simply having the php execute: print "hi ! $do $this $here<br />";
but when i save the function it gives an error:
Fatal error: Smarty error: [in smartymarkupplugin:478814949 line 2]: [plugin] unknown tag - 'myFunction' (core.load_plugins.php, line 118) in /home/content/e/d/s/edscholl/html/blog/bundled-libs/Smarty/libs/Smarty.class.php on line 1088
2: is there any special syntax required for calling the smarty function from within javascript?
thanks!
-
eggt
-
by eggt » Mon Dec 05, 2005 4:08 am
To clarify #2 above, i want to conditionally call a smarty function from w/in javascript. If I have {myFunction do=1 this=2 here=3} within a conditional function within my page, it still always gets called.
thanks
-

garvinhicking
- Core Developer
-
- Posts: 26675
- Joined: Tue Sep 16, 2003 9:45 pm
- Location: Cologne, Germany
-
by garvinhicking » Mon Dec 05, 2005 11:38 am
First, you must register your custom functions within the config.inc.php template file, as mentioned in the Technical Docs on www.s9y.org about "Special Smarty Functions".
About number 2: Smarty get's executed before javascript. It's just like PHP: You cannot call PHP functions from within javascript. You must make additional HTTP page requests if you only want to conditionally include content; or use AJAX features. But in most cases, you should try to do the conditional stuff within PHP/Smarty, not within javascript.
Best regards,
Garvin
-
eggy
-
by eggy » Mon Dec 05, 2005 6:46 pm
garvinhicking wrote:First, you must register your custom functions within the config.inc.php template file, as mentioned in the Technical Docs on www.s9y.org about "Special Smarty Functions". About number 2: Smarty get's executed before javascript. It's just like PHP: You cannot call PHP functions from within javascript. You must make additional HTTP page requests if you only want to conditionally include content; or use AJAX features. But in most cases, you should try to do the conditional stuff within PHP/Smarty, not within javascript. Best regards, Garvin
thanks for the prompt reply as always garvin- i am registering the custom functions in the config.inc.php; that's where all my php code is living... when i save an entry, i'm getting the errors above. but the functions work fine in the entries... should i just ignore the errors?
about #2- that's what i figured, i was just hoping there would be a easy cheat to get it to be called w/in the javascript. =D
-

garvinhicking
- Core Developer
-
- Posts: 26675
- Joined: Tue Sep 16, 2003 9:45 pm
- Location: Cologne, Germany
-
by garvinhicking » Tue Dec 06, 2005 2:22 pm
Eggy: Great, in fact you hit a bug there
The 'config.inc.php' file is not called when previewing/saving an entry.
So you can edit your include/genpage.inc.php file and remove those lines:
- Code: Select all
// For advanced usage, we allow template authors to create a file 'config.inc.php' where they can // setup custom smarty variables, modifiers etc. to use in their templates. @include_once $serendipity['smarty']->config_dir . '/config.inc.php';
Instead place them at the end, just before "return true" of your serendipity_smarty_init() function found in the include/functions_smarty.inc.php file. Then it should all work.
Please tell me if that works out for you, so I'll commit it to our repository!
Regards,
Garvin
-
eggy
-
by eggy » Thu Dec 08, 2005 6:19 pm
yup, that works. thanks!
Return to General discussions
Who is online
Users browsing this forum: No registered users and 1 guest
|