“Customizable template option variables”

Discussion corner for Developers of Serendipity.
Post Reply
User avatar
yellowled
Regular
Posts: 7083
Joined: Fri Jan 13, 2006 12:46 pm
Location: Eutin, Germany
Contact:

“Customizable template option variables”

Post by yellowled » Tue Jul 23, 2013 7:35 pm

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
amazon Wishlist - Serendipity-Podcast (German only, sorry)

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

Re: “Customizable template option variables”

Post by Timbalu » Tue Jul 23, 2013 7:52 pm

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

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

Re: “Customizable template option variables”

Post by Timbalu » Tue Jul 23, 2013 8:04 pm

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

User avatar
onli
Regular
Posts: 2260
Joined: Tue Sep 09, 2008 10:04 pm
Contact:

Re: “Customizable template option variables”

Post by onli » Tue Jul 23, 2013 8:13 pm

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.

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

Re: “Customizable template option variables”

Post by Timbalu » Tue Jul 23, 2013 8:24 pm

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

User avatar
kleinerChemiker
Regular
Posts: 765
Joined: Tue Oct 17, 2006 2:36 pm
Location: Vienna/Austria
Contact:

Re: “Customizable template option variables”

Post by kleinerChemiker » Tue Jul 23, 2013 10:42 pm

Why not useing Smarty for the css files? Smarty can even cache the file/output.

User avatar
onli
Regular
Posts: 2260
Joined: Tue Sep 09, 2008 10:04 pm
Contact:

Re: “Customizable template option variables”

Post by onli » Tue Jul 23, 2013 11:35 pm

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.

User avatar
Don Chambers
Regular
Posts: 3638
Joined: Mon Feb 13, 2006 3:40 am
Location: Chicago, IL, USA
Contact:

Re: “Customizable template option variables”

Post by Don Chambers » Mon Aug 05, 2013 4:34 pm

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>

User avatar
yellowled
Regular
Posts: 7083
Joined: Fri Jan 13, 2006 12:46 pm
Location: Eutin, Germany
Contact:

Re: “Customizable template option variables”

Post by yellowled » Mon Aug 05, 2013 6:06 pm

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
amazon Wishlist - Serendipity-Podcast (German only, sorry)

User avatar
Don Chambers
Regular
Posts: 3638
Joined: Mon Feb 13, 2006 3:40 am
Location: Chicago, IL, USA
Contact:

Re: “Customizable template option variables”

Post by Don Chambers » Mon Aug 05, 2013 6:36 pm

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.

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

Re: “Customizable template option variables”

Post by Timbalu » Mon Aug 05, 2013 7:28 pm

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

User avatar
yellowled
Regular
Posts: 7083
Joined: Fri Jan 13, 2006 12:46 pm
Location: Eutin, Germany
Contact:

Re: “Customizable template option variables”

Post by yellowled » Mon Aug 05, 2013 7:33 pm

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
amazon Wishlist - Serendipity-Podcast (German only, sorry)

User avatar
Don Chambers
Regular
Posts: 3638
Joined: Mon Feb 13, 2006 3:40 am
Location: Chicago, IL, USA
Contact:

Re: “Customizable template option variables”

Post by Don Chambers » Mon Aug 05, 2013 9:52 pm

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:

User avatar
yellowled
Regular
Posts: 7083
Joined: Fri Jan 13, 2006 12:46 pm
Location: Eutin, Germany
Contact:

Re: “Customizable template option variables”

Post by yellowled » Thu Jan 09, 2014 6:07 pm

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
amazon Wishlist - Serendipity-Podcast (German only, sorry)

Post Reply