Page 1 of 1

#5279 cms_stylesheet doesn't use new logic with "name" parameter not solved

Posted: Mon Oct 11, 2010 9:48 pm
by codegrunt
Howdy.  I was not sure where to post this as the announcement forum is read only.  If a mod has a better spot for this I would appreciate it if you could move it to the correct location for me.

I am quite new to CMSMadeSimple so am having to follow the documentation pretty closely while I learn the system.  I have been trying to come up with a methodology to avoid having to have a separate template *and* stylesheet for each to page to be able to support different colours for different sections of the site.  I tried adding some logic at the top of the stylesheet via custom tags to get the current section and set the colours accordingly but caching breaks this (since they are cached on the first run through every section gets the same variable values). 

So I decided to try to use the {cms_stylesheet name="foobar"} approach with the name value being set by the calling template dynamically.  However, after multiple variations and the stylesheet not showing up in the page output, I ended up searching the codebase to see how cms_stylesheet was being generated.  After adding some debug statements to get the query and arguments I noticed the following:

When a "name" parameter is passed to {cms_stylesheet}, the method "smarty_cms_function_cms_stylesheet()" in the file ./plugins/function.cms_stylesheet.php will create the following query to lookup the stylesheet:

Code: Select all

SELECT DISTINCT A.css_id,A.css_name,A.css_text,A.modified_date,
        A.media_type,B.assoc_order 
    FROM cms_css A, cms_css_assoc B
    WHERE A.css_id = B.assoc_css_id AND A.css_name = "my_stylesheet_name" ORDER BY B.assoc_order
The problem here is that this assumes that the template has been associated with a page explicitly.  If it has not, the join will fail because the template will not have a record in the "cms_css_assoc" table yet.  So if you create a new stylesheet it will not be callable via the name parameter.

I am not sure whether to call this a bug or a documentation problem (I am leaning towards it being a bug) but in the meantime the work around is to create a dummy template and then associate the special use stylesheet with it.

I expect the fix here is to just change the logic to skip the join if the name parameter is passed (and exists) but I have not delved deep enough to know if that would lead to any issues elsewhere in the codebase.

Cheers

Re: #5279 cms_stylesheet doesn't use new logic with "name" parameter not solved

Posted: Mon Oct 11, 2010 10:19 pm
by Dr.CSS
If you are having problems with {cms_stylesheet} you may want to try {stylesheet name='nameofit'} as it still works, they are working on 1.9 and this is one of the bugs to be fixed...

Re: #5279 cms_stylesheet doesn't use new logic with "name" parameter not solved

Posted: Mon Oct 11, 2010 11:32 pm
by Jeff
The problem is when the stylesheet isn't associated with any templates.

The work around is the just attach the stylesheet to a template that isn't used that why it will have a record in the cms_css_assoc table.