Why would I want to do this?
I have a client who wants to experiment with different background colors in the content sections of her page. I don't want to give her full editing control over the stylesheets via the permissions scheme, but I thought if I could write a GCB that had just the appropriate well-commented style rules, I could insert that into the stylesheet, and my client could edit the GCB instead.
Something like this:
{global_content name="background-colors"}
/*
Edit the 6-character HTML color code below to change the background color of the righthand content section on all pages. You can use this page http://www.colordic.org to get started, or do a Google search for 'html color codes' to find other references.
*/
div#content2 {background-color: #FFFFFF; }
I'm thinking this may not work because of the curly braces that have to surround the GCB call. The stylesheet would interpret these as demarcating a style rule. Hmmmm...
Can a Global Content Block be used in a stylesheet?
Can a Global Content Block be used in a stylesheet?
Last edited by jmcgin51 on Wed Sep 17, 2008 2:08 am, edited 1 time in total.
Re: Can a Global Content Block be used in a stylesheet?
anyone........anyone??
-
nhaack
Re: Can a Global Content Block be used in a stylesheet?
hi jmcgin51,
well, theoretically yes. Let's say you have a section in your site for "stylesheet pages".
1: Home
1.1: Sub Page
2: Other Content
3: Stylesheets
3.1: Single Stylesheet
Speak: You have a template with nothin in it, except the tag {content} and the page alias is "stylesheet1". Just do all the kinky stuff you want to do in this page so you would get your CSS data. Of course you could also use a houndred content blocks there to give each editable field an own editing option in the backend.
Or, for GCB, just place all the GCB calls you need into your CSS code (where you would want it to appear) and save it as an own template. Attach this template to a page and address the page as described below.
Now refer to the page as stylesheet in your actual page codes head area as follows:
Now you get your dynamically created CSS into a page. However, you will probably loose some performance. But it is a theoretical solution to your problem.
What would you like to do? Probably there is another way to accomplish this?
Best
Nils
well, theoretically yes. Let's say you have a section in your site for "stylesheet pages".
1: Home
1.1: Sub Page
2: Other Content
3: Stylesheets
3.1: Single Stylesheet
Speak: You have a template with nothin in it, except the tag {content} and the page alias is "stylesheet1". Just do all the kinky stuff you want to do in this page so you would get your CSS data. Of course you could also use a houndred content blocks there to give each editable field an own editing option in the backend.
Or, for GCB, just place all the GCB calls you need into your CSS code (where you would want it to appear) and save it as an own template. Attach this template to a page and address the page as described below.
Now refer to the page as stylesheet in your actual page codes head area as follows:
Code: Select all
<link rel="STYLESHEET" type="text/css" href="index.php?page=stylesheet1" />
What would you like to do? Probably there is another way to accomplish this?
Best
Nils
Last edited by nhaack on Thu Sep 18, 2008 4:08 pm, edited 1 time in total.
-
calguy1000
- Support Guru

- Posts: 8169
- Joined: Tue Oct 19, 2004 6:44 pm
Re: Can a Global Content Block be used in a stylesheet?
Code: Select all
<div style="background-color: {global_content name='mybackgroundcolor'}">
blah
blah
blah
</div>Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
Re: Can a Global Content Block be used in a stylesheet?
Calguy, thanks for that suggestion; I hadn't even thought of modifying the template. Blinders on, I guess.
But your example would work only directly in a content page or template; I don't think it would in a separate stylesheet.
Here's the syntax that I think would have to be used in a stylesheet, but it doesn't work:
***
div#content2 {background-color: {global_content name='rh_background_color'}; }
***
(where {global_content name='rh_background_color'} = #000000)
If I need to, I'll add your suggested code to the template, but I'd still prefer to do it in the stylesheet if possible. If stylesheets can't process Smarty, then I guess I have to use the template method. Oh, but this gets back to the issue that I can't modify my template due to the "template name already exists" error. *sigh*
Thanks again (and to you also, Nils)!
But your example would work only directly in a content page or template; I don't think it would in a separate stylesheet.
Here's the syntax that I think would have to be used in a stylesheet, but it doesn't work:
***
div#content2 {background-color: {global_content name='rh_background_color'}; }
***
(where {global_content name='rh_background_color'} = #000000)
If I need to, I'll add your suggested code to the template, but I'd still prefer to do it in the stylesheet if possible. If stylesheets can't process Smarty, then I guess I have to use the template method. Oh, but this gets back to the issue that I can't modify my template due to the "template name already exists" error. *sigh*
Thanks again (and to you also, Nils)!
-
calguy1000
- Support Guru

- Posts: 8169
- Joined: Tue Oct 19, 2004 6:44 pm
Re: Can a Global Content Block be used in a stylesheet?
Won't work in the stylesheet.
Smarty doesn't process the stylesheets.
Smarty doesn't process the stylesheets.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
-
nhaack
Re: Can a Global Content Block be used in a stylesheet?
Mhhh... but what about making a page serve the CSS? Would that be a no go? I'll try to better describe my approach for better understanding.
1) You add your normal stylesheet to your template as you would normally do, except that you cut out the style instructions for the specific elements you want to be editable by a user.
2) You create a template called "Editable User CSS" with a code like this (and the template code only contains this, nothing but your styles and a little arround it, no html at all):
With the help of the {literal} tag, we cut around the css and "insert" the required fields. As we assign the content of the regular content field only to a variable, it will not jump into the CSS even if the tag is left out of the template.
3) Create a new page called "The editable CSS", pick our template "Editable User CSS" and initially fill out the first content block (the standard one you can not get rid of - i think) with a little help text. For every value your user can set, he/she gets a little edit field to put the value into. Set "Show in menu" in page-options to "no", set your required user rights and save the page.
4) Add the stylesheet-page to the templates you want to allow your users to make changes to by adding the stylesheet in the template html like this:
This way one could get a nice interface to make custom settings to a site for selected users. They can make changes anytime they wish. See below for a sample screenshot:

I ran it on a sample install. And it seems to work. However it doesn't seem to work that good in Firefox, though I guess it is just a little thing I can't put my finger on.
What do you think?
Best
Nils
1) You add your normal stylesheet to your template as you would normally do, except that you cut out the style instructions for the specific elements you want to be editable by a user.
2) You create a template called "Editable User CSS" with a code like this (and the template code only contains this, nothing but your styles and a little arround it, no html at all):
Code: Select all
{process_pagedata}
{content assign="content_var"}
{literal}
body {
background-color: #FFFFFF;
}
#content {
background-color:
{/literal}
{content block="YourFieldName" oneline="true"}
{literal}
}
{/literal}
3) Create a new page called "The editable CSS", pick our template "Editable User CSS" and initially fill out the first content block (the standard one you can not get rid of - i think) with a little help text. For every value your user can set, he/she gets a little edit field to put the value into. Set "Show in menu" in page-options to "no", set your required user rights and save the page.
4) Add the stylesheet-page to the templates you want to allow your users to make changes to by adding the stylesheet in the template html like this:
Code: Select all
<__html>
<head>
<title>{sitename} - {title}</title>
{metadata}
{stylesheet}
<!-- Now comes the generated CSS -->
<link rel="stylesheet" type="text/css" href="index.php?page=the-editable-css" />
</head>
</__body>
Some static template text.
<div id="content">
{Content}
</div>
<__body>
</__html>

I ran it on a sample install. And it seems to work. However it doesn't seem to work that good in Firefox, though I guess it is just a little thing I can't put my finger on.
What do you think?
Best
Nils
Last edited by nhaack on Thu Sep 18, 2008 10:23 pm, edited 1 time in total.
Re: Can a Global Content Block be used in a stylesheet?
Calguy - thanks for confirming.
Nils - very cool. I never would have thought of doing it that way, but it certainly seems workable. And ultimately maybe better, because I don't have to give users rights to edit GCBs.
Thanks!!
Nils - very cool. I never would have thought of doing it that way, but it certainly seems workable. And ultimately maybe better, because I don't have to give users rights to edit GCBs.
Thanks!!

