|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
phelar Smarty n00b
Joined: 23 Sep 2015 Posts: 2
|
Posted: Wed Sep 23, 2015 2:14 am Post subject: Auto inject to block from plugin |
|
|
I have 2 Smarty templates, a "master.tpl" and a "child.tpl".
The master looks something like:
Code: | <html>
<head>
{block name = "css"}{/block}
</head>
<body>
{block name = "body"}{/block}
</body>
</html> |
And the child template looks like:
Code: | {extends file="master.tpl"}
{block name = "css"}
<link rel = "stylesheet" type = "text/css" href = "css_for_plugin.css">
{/block}
{block name = "body"}
{plugin_that_requires_css}
{/block} |
My issue is I want the css to be injected into this block from the plugin and not have to explicitly include the css in the template, the idea being that as the plugin evolves and needs more or less css the plugin handles all the css prerequisites.
My thought is do have the plugin do something like the following:
Code: | function smarty_function_plugin_that_requires_css($params, &$smarty){
//this is conceptually what I want to do
$smarty.block.parent.css.append('<link rel = "stylesheet" type = "text/css" href = "css_for_plugin.css">');
} |
Is this even possible? |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Wed Sep 23, 2015 5:14 am Post subject: |
|
|
It is unnecessary.
Just add everything to CSS and don't change it on the fly.
Changing CSS back and forth you lose more in bandwidth than you could possible think to gain.
You will need specific server configuration to allow shorter caching times and you will need to tell about it to the browser, which normally expects CSS to be rarely changing and could blindly cache it without even checking on that presumption. |
|
Back to top |
|
phelar Smarty n00b
Joined: 23 Sep 2015 Posts: 2
|
Posted: Thu Sep 24, 2015 9:08 pm Post subject: |
|
|
I understand your reasoning, and I'm not anticipating the css to change frequently, possibly months or years between changes.
The main idea behind this is to separate the css from the template itself. The way we have it set up, there's a generic master template and numerous child templates that could include any number of plugins, and in hoping to keep management of the css/js to a minimum I was hoping to make it to where the plugin tells the template what css/js files it needs and the template is agnostic to it all.
As far as the HTML that's generated, it should be consistent across every request, but as the plugin changes and I need to add/remove files that are needed, I would like to just change the plugin instead of changing every child template that includes that plugin.
There could potentially be hundreds of child templates that could be affected. |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Fri Sep 25, 2015 12:35 am Post subject: |
|
|
Again, just combine everything into a single CSS file, deflate it and serve it as that.
There's lots of deployment tools to process and combine JS and CSS files into smaller packages.
What you are trying to do people discarded years ago as unviable and unmanageable burden. |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|