Forums / Cotonti / Extensions / CSS called by plugin

Davide
#1 2012-11-22 23:37

Hi,

I am writing a plugin for Cotonti that I want to have use its own CSS file.  Can someone please advise how I call the CSS file..I.e which plugin file do I need to add an 'include' statement and anything else I need to do.  I don't want the CSS to be in my skin/theme CSS file.

I saw this was done in the 'tags' plugin but didn't quite follow.  My plugin won't have as many .php files

many thanks

David

lukgoh
#2 2012-11-23 08:56

I was going to say in tags.resources, but it looks like its just a comment?

/*$R['tags_code_style'] = '<link rel="stylesheet" type="text/css" href="'.$cfg['plugins_dir'].'/tags/style.css" />';*/

 

Added 2 minutes later:

Ignor that, its in tags.rc.php:

cot_rc_add_file($cfg['plugins_dir'] . '/tags/tpl/tags.css');

 

Davide
#3 2012-11-23 09:47

Hi, yes, thanks, I see that...problem is, my plugin doesn't have a resources file (it's a plugin adapted from LDU/Seditio).

I'm using a very simple set of .php files in my plugin and wondered if it could go in the main php plugin file or the config.php file?

Thanks again

David

This post was edited by Davide (2012-11-23 13:36, 11 years ago)
Trustmaster
#4 2012-11-23 17:13

If you only want to use it on your plugin page and you are not going to consolidate it with other site stylesheets, then you can simply add it using cot_rc_link_footer() function in your main php file:

cot_rc_link_footer($cfg['plugins_dir'] . '/myplug/tpl/myplug.css')

 

May the Source be with you!
esclkm
#5 2012-11-23 18:00

footer is not valid for html

littledev.ru - мой маленький зарождающийся блог о котонти.
снижение стоимости программирования и снижение стоимости производства разные вещи. Первое можно скорее сравнить с раздачей работникам дешевых инструментов, чем со снижением зарплаты
Davide
#6 2012-11-23 18:13

Yes, the CSS is 'just' for a particular plugin.  I thought there would be a way of calling it from the plugin itself.  I know I can't use include() as this just prints the CSS to screen as opposed to applying it to the output from the plugin.

pas I said, I saw this was done for the 'tags' plugin but this is a very complex plugin. Mine is very simple and only outputs through the .tpl for the plugin, under plugin.php page. (This is a standalone plugin, I.e it doesn't hook or tag into any other parts of Cotonti, just onto the plugin page)

Many thanks

David

Trustmaster
#7 2012-11-23 19:38

I forgot that in a plugin standalone part you can also do cot_rc_link_file():

cot_rc_link_file($cfg['plugins_dir'] . '/myplug/tpl/myplug.css');

 

May the Source be with you!
Davide
#8 2012-11-24 13:50

I'll give this a go.  Thank you for your help

 

David

Added 2 hours later:

Uhm....slight problem,

Genoa doesnt have the cot_rc_link_file() function in functions.php...can I just copy/paste that function from Sienna's functions.php and paste into Genoa's functions.php and everything will be ok?

David

This post was edited by Davide (2012-11-24 15:36, 11 years ago)
Macik
#9 2012-11-25 20:10

Nop, `cot_rc_link_file` is use other `cot_rc_*` functions.

But, as I remember, you can use something like this:

$out['compopup'] .= '<link href="'.$file.'" type="text/css" rel="stylesheet" />\n'; 

where $file contains filename with path to your CSS.

https://github.com/macik
правильный хостинг — https://goo.gl/fjCa1F
Davide
#10 2012-11-25 23:06

Macik,

Thanks. Where should I include this line, in my main pluginname.php?

How/when is $out['compopup'] parsed?

as an aside, anyone have an overview of how Cotonti starts up?, by this I mean, the sequence of operations it runs through before it parses and presents the 'homepage' of the website?

thanks

david

This post was edited by Davide (2012-11-26 01:44, 11 years ago)
Trustmaster
#11 2012-11-26 06:30

Ah, so you're using Genoa. Then things are slightly different because in Genoa your main pluginname.php is executed after the header part is rendered. So you need to add another part to your plugin to add that CSS file to header:

<?php
/* ====================
[BEGIN_SED_EXTPLUGIN]
Code=pluginname
Part=header
File=pluginname.header
Hooks=header.main
Tags=header.tpl:{HEADER_COMPOPUP}
Order=10
[END_SED_EXTPLUGIN]
==================== */

defined('SED_CODE') or die('Wrong URL');

if (defined('SED_PLUG') && $e == 'pluginname')
{
	$out['compopup'] .= '<link rel="stylesheet" type="text/css" href="'.$cfg['plugins_dir'].'/pluginname/tpl/style.css" />';
}

 

May the Source be with you!
Davide
#12 2012-11-29 14:04
Thank you, I'll give this a go.

davide

Added 3 weeks later:

No...sadly, this wont work...my plugin doesn't have that part...what I did do was put:

  $echo "<link href='plugins/standard/pluginname/css/style.css'  type='text/css' rel='stylesheet'>";

into my pluginname.config.php and it worked a treat.

Thank you

david

This post was edited by Davide (2012-12-21 07:15, 11 years ago)
lukgoh
#13 2012-12-21 09:30

The correct way would be to create a php page called pluginname.header.php and copy and paste Trustmaster's code (changing the parts to match up with your plugin.) 

Luke.

Davide
#14 2012-12-21 19:38

Agreed!

once it's all completed and tested, I'll do that.

thanks for your input

kind regards

david