“Customizable template option variables”

Discussion corner for Developers of Serendipity.
Post Reply
yellowled
Regular
Posts: 7111
Joined: Fri Jan 13, 2006 11:46 am
Location: Eutin, Germany
Contact:

“Customizable template option variables”

Post by yellowled »

So I came up with another weird thing for which I don't have a name yet which would in my opinion make for an awesome feature in S9y. You guys all know the drill, right? First I explain this in a clumsy, elaborate, extensive manner, and then Garvin goes: “Oh, we already have that.” :mrgreen:

Here's what I'd love to have:

Our style.css is being “parsed” (or whatever you crazy PHP guys call it) by serendipity.css.php. Among other magical things, this process substitutes {TEMPLATE_PATH} by the actual path to the templates directory, making it possible to reference CSS assets like background images properly.

What if there were other template-based variables like this which would also be parsed there?

Example: in a template's theme options, I could have an option “Primary color” which would contain a corresponding input field with the default value of, say, #ff0000. But users could change this to, say, #0000ff, because nobody really likes red anyway, right? Blue is much cooler. And what if in the style.css the template author could use something like

Code: Select all

a,
a:visited {
    color: {PRIMARY_COLOR};
}
and serendipity.css.php (or the template's config.inc.php or whatever) would just replace that by whatever value a corresponding theme option would hold?

That way, users could very easily tweak templates to their liking without having to edit code or having to use a user.css. (And I would never have to write a user.css generator like the one for 2k11 again, which would be super awesome, because seriously, that was a major pain in the ass.) And I can think of some more things to do with this …

Is this doable, reasonable, does it even make sense? Anybody up for this?

YL
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: “Customizable template option variables”

Post by Timbalu »

Yes, possible!
The only limit is the horizont, I'd say... ;-) (and the much of requests taking this, I presume)
Regards,
Ian

Serendipity Styx Edition and additional_plugins @ https://ophian.github.io/ @ https://github.com/ophian
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: “Customizable template option variables”

Post by Timbalu »

Couldn't we do this possibly in that template config.inc.php file too, somewhere like this:

Code: Select all

       $tfile = serendipity_getTemplateFile('style_dynamic.css', 'serendipityPath');
       if($tfile) {
           $search = array('{PRIMARY_COLOR}', '{SECONDARY_COLOR}');
           $replace = array('templates/' . $serendipity['theTemplate'] . '/', $serendipity['aPluginName']['optionPluginPath']); (this as an example on how to include from different contents)
           $tfilecontent = str_replace($search, $replace, @file_get_contents($tfile));
       }
(slight modified example taken from https://github.com/s9y/additional_plugi ... .php#L1096)
and then append this to the serendipity.css file stream somehow?
Regards,
Ian

Serendipity Styx Edition and additional_plugins @ https://ophian.github.io/ @ https://github.com/ophian
onli
Regular
Posts: 2828
Joined: Tue Sep 09, 2008 10:04 pm
Contact:

Re: “Customizable template option variables”

Post by onli »

Code: Select all

function serendipity_printStylesheet($file, $dir = '') {
    global $serendipity;
    return "/* $dir  */\n" . str_replace(
             array(
               '{TEMPLATE_PATH}',
               '{LANG_DIRECTION}'
             ),

             array(
               dirname($dir) . '/',
               LANG_DIRECTION
             ),

             @file_get_contents($file, 1));
}
That is the code currently replacing {TEMPLATE_PATH} (https://github.com/s9y/Serendipity/blob ... ss.php#L36). I think to implement a feature like this, it would be best to include the template-variables there - the name as the identifier, the value as the replacement.

It sure would impact performance a bit.
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: “Customizable template option variables”

Post by Timbalu »

Timbalu wrote:and then append this to the serendipity.css file stream somehow?
I bet this would actually be a nice delegation for the "faked plugins" usage (search that thread) combined with the 'css' frontend hook, to do this right now! :wink: (*)

I leave the :mrgreen: for Garvin...!

(*) and also the new template hook with 1.7.1
Regards,
Ian

Serendipity Styx Edition and additional_plugins @ https://ophian.github.io/ @ https://github.com/ophian
kleinerChemiker
Regular
Posts: 765
Joined: Tue Oct 17, 2006 2:36 pm
Location: Vienna/Austria
Contact:

Re: “Customizable template option variables”

Post by kleinerChemiker »

Why not useing Smarty for the css files? Smarty can even cache the file/output.
onli
Regular
Posts: 2828
Joined: Tue Sep 09, 2008 10:04 pm
Contact:

Re: “Customizable template option variables”

Post by onli »

Yes, that surely is an option (and coherent with the serendipity_editor.js.tpl), but maybe a bit too expensive when we only need to replace a few strings. CSS should be cached anyway.
Don Chambers
Regular
Posts: 3652
Joined: Mon Feb 13, 2006 2:40 am
Location: Chicago, IL, USA
Contact:

Re: “Customizable template option variables”

Post by Don Chambers »

Timbalu wrote:..... and also the new template hook with 1.7.1
I have been "out of the loop" for awhile. What new template hook?


Its probably not as pretty, but you can do something like this inline in a template's index.tpl:

Code: Select all

<style type="text/css">
     a,
     a:visited {ldelim}
         color: {$template_option.PRIMARY_COLOR};
{rdelim}
</style>
=Don=
yellowled
Regular
Posts: 7111
Joined: Fri Jan 13, 2006 11:46 am
Location: Eutin, Germany
Contact:

Re: “Customizable template option variables”

Post by yellowled »

Don Chambers wrote:Its probably not as pretty, but you can do something like this inline in a template's index.tpl:
That's what I want to avoid. Inline styles are bad. :)

YL
Don Chambers
Regular
Posts: 3652
Joined: Mon Feb 13, 2006 2:40 am
Location: Chicago, IL, USA
Contact:

Re: “Customizable template option variables”

Post by Don Chambers »

yellowled wrote:
Don Chambers wrote:Its probably not as pretty, but you can do something like this inline in a template's index.tpl:
That's what I want to avoid. Inline styles are bad. :)

YL
I know, but if someone else was following this thread, and wanted the ability RIGHT NOW, then this was a way to do it.

I just thought of something else somewhat related... {TEMPLATE_PATH} only works (AFAIK) in a template's style.css file. It might be nice if this, as well as any future {TEMPLATE_CSS_OPTIONS} also worked in additional css files should a particular template wish to include them.
=Don=
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: “Customizable template option variables”

Post by Timbalu »

Don Chambers wrote:I have been "out of the loop" for awhile. What new template hook?
http://board.s9y.org/viewtopic.php?f=11&t=19454
Regards,
Ian

Serendipity Styx Edition and additional_plugins @ https://ophian.github.io/ @ https://github.com/ophian
yellowled
Regular
Posts: 7111
Joined: Fri Jan 13, 2006 11:46 am
Location: Eutin, Germany
Contact:

Re: “Customizable template option variables”

Post by yellowled »

Don Chambers wrote:It might be nice if this, as well as any future {TEMPLATE_CSS_OPTIONS} also worked in additional css files should a particular template wish to include them.
Multiple CSS files are bad as well. :)

But if we some day get a feature to combine multiple CSS files in serendipity_css.php, then this could be useful.

YL
Don Chambers
Regular
Posts: 3652
Joined: Mon Feb 13, 2006 2:40 am
Location: Chicago, IL, USA
Contact:

Re: “Customizable template option variables”

Post by Don Chambers »

yellowled wrote:Multiple CSS files are bad as well. :)

Not always. Sometimes for code maintainability, or logical understanding, the benefits of using multiple files could out weigh the negatives. This is also true for including a secondary file within a primary file, rather than having all the code in a single, larger file.
yellowled wrote:But if we some day get a feature to combine multiple CSS files in serendipity_css.php, then this could be useful.YL
Definitely! :wink:
=Don=
yellowled
Regular
Posts: 7111
Joined: Fri Jan 13, 2006 11:46 am
Location: Eutin, Germany
Contact:

Re: “Customizable template option variables”

Post by yellowled »

Has anyone ever actually tried to implement this or has it gotten under the rails? I'd still like to see this in s9y. :-)

YL
Post Reply