template_path parsing

Creating and modifying plugins.
Post Reply
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

template_path parsing

Post by Timbalu »

Hi

Is there any solution to get smarty parsing plugin css files in your template folder using

Code: Select all

background: url('{TEMPLATE_PATH}img/foo.png')
which works in the admin panel but does not work for a plugin css file inside your template folder

Code: Select all

$tfile = serendipity_getTemplateFile('style_myplugin_backend.css', 'serendipityPath');

if (!$tfile || $tfile == 'style_myplugin_backend.css') {
     $tfile = dirname(__FILE__) . '/style_myplugin_backend.css';
}

echo file_get_contents($tfile);
If you put it in template user.css you can just do

Code: Select all

background: url('img/foo.png')
Is this behavior by design or did I understand something wrong?

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

Re: template_path parsing

Post by garvinhicking »

Hi!

You only need TEMPLATE_PATH in the style.css, because it is loaded through serendipity.css.php and its relative URL is inside the main root directory. Unlike all other CSS files which are loaded through the real path they live in, so you can reference any paths relatively to that CSS file (img/...). So if you like to load a template dependant file, you would need to put the CSS file inside the template directory.

The CSS files are loaded directly, so there is no way for PHP to kick in. If you need any replacement, you would need to use an event plugin with "external_plugin" hook to create a custom URL like index.pph?/plugin/mycss which uses PHP to output/read any CSS files.

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/
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: template_path parsing

Post by Timbalu »

Hi Garvin

I don't really understand...
I use a event plugin hook inside the event plugin I am working on with case 'css'.
The file style_myplugin_backend.css is located in my plugin folder and in the bulletproof template folder where it is loaded correctly and I can't use url('img/foo.png') nor url('{TEMPLATE_PATH}img/foo.png').

If I add the external plugin hook

Code: Select all

case 'external_plugin':
       switch($eventData) {
             ???
       }
       return true;
       break;
what do I need to put in there to let smarty parse the template/style_myplugin_backend.css?

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

Re: template_path parsing

Post by garvinhicking »

Hi!

In your 'css' event hook you would need to replace the variables yourself; have a look at how serendipty.css.php parses the path.

There's no smarty parsing, it's only a str_replace() on two fixed variables.

HTH,
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/
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: template_path parsing

Post by Timbalu »

Hi Garvin

Thats it! No use for "external_plugin". Thanks for the help!
Ian

Code: Select all

case 'css':
       ...
       $tfile = serendipity_getTemplateFile('style_myplugin_backend.css', 'serendipityPath');
       ...
       echo str_replace('{TEMPLATE_PATH}', 'templates/' . $serendipity['defaultTemplate'] . '/', @file_get_contents($tfile));
       ....
Post Reply