View previous topic :: View next topic |
Author |
Message |
tacman1123 Smarty Rookie
Joined: 11 Mar 2004 Posts: 8 Location: Washington, DC
|
Posted: Wed Feb 23, 2011 12:22 pm Post subject: too many shorthand attributes with {block ... append} |
|
|
I have a fairly template template where I'm trying to append some additional css to an earlier block, but keep getting this error message
Code: |
{block name='css_head'}
<!--[if IE 6]><link rel="stylesheet" type="text/css" href="css/ie6.css" media="screen" /><![endif]-->
<!--[if IE 7]><link rel="stylesheet" type="text/css" href="css/ie.css" media="screen" /><![endif]-->
<!-- the css will go here after it's been loaded -->
{/block}
{block name='css_head' append} | "too many shorthand attributes' in C:\usr\sites\Smarty\distribution\libs\sysplugins\smarty_internal_templatecompilerbase.php on line 433
Any help would be appreciated, this is a show-stopper right now!
Tac |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
|
Back to top |
|
tacman1123 Smarty Rookie
Joined: 11 Mar 2004 Posts: 8 Location: Washington, DC
|
Posted: Wed Feb 23, 2011 8:16 pm Post subject: |
|
|
Is it possible, then, to replace a block defined earlier in the template?
I want to put the css at the top of the page, but the layout doesn't know what css files are going to be needed. I have a custom function that helps me keep track of them, but I don't want the child template to have to add the css if there's a way for the parent (layout.tpl) to just automatically add any additional css that's been designated as needed.
Is this possible?
Tac |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Wed Feb 23, 2011 9:04 pm Post subject: |
|
|
Something like this?
layout.tpl:
Code: | ...
<head>
{block name="css"}{/block}
</head>
... |
child template:
Code: | {extends file="layout.tpl"}
{block name="css"}
{my_css_func}
{/block} |
So your child template calls the my_css_func, which in turn spits out the appropriate text to include css files in the head of the page. Or, just include the css manually in the child template. or include another tpl that contains the logic to load css. whatever works. |
|
Back to top |
|
Mikaroz Smarty n00b
Joined: 06 Jun 2011 Posts: 3
|
Posted: Mon Jun 06, 2011 7:41 pm Post subject: |
|
|
Hi
i have a similar problem
http://stackoverflow.com/questions/4282511/smarty3-block-append-in-included-template
my structure is as follows
#base.tpl
Code: |
....
<head>
{block name='css_aggiuntivo'}{/block}
</head>
.....
<header>
{block name='header'}{/block}
</header>
|
#home.tpl
Code: |
{extends file='base.tpl'}
{block name='header'}
{include 'menu_top.tpl'}
{/block}
|
#menu_top.tpl
Code: |
{block name='css_aggiuntivo'}
<link rel="stylesheet" href="css/menu_top.css" type="text/css">
{/block}
<div id="menuTop">
......
</div>
|
#index.php
Code: |
$smarty->display('home.tpl');
|
I would like to put different .tpl files in home.tpl (menu_top.tpl, nav_news.tpl, menu_bottom.tpl etc..)
how can I do?
Would be better to preload data with links to the css in arrays and insert them directly into the block css_aggiuntivo in home.tpl?
sorry for my English[url][/url] |
|
Back to top |
|
rodneyrehm Administrator
Joined: 30 Mar 2007 Posts: 674 Location: Germany, border to Switzerland
|
Posted: Mon Jun 06, 2011 9:27 pm Post subject: |
|
|
Smarty's template inheritance is processed before the parser even knows about your {include}. Thus it cannot handle {block}s in included templates. That is, unless the included template doesn't extend another template itself. |
|
Back to top |
|
Mikaroz Smarty n00b
Joined: 06 Jun 2011 Posts: 3
|
Posted: Tue Jun 07, 2011 9:11 am Post subject: |
|
|
I understand the problem.
is there a way to do this? what is the best practice? |
|
Back to top |
|
rodneyrehm Administrator
Joined: 30 Mar 2007 Posts: 674 Location: Germany, border to Switzerland
|
Posted: Tue Jun 07, 2011 9:20 am Post subject: |
|
|
It is (currently) not possible to {include} a template and have its {block}s used in the current template inheritance chain. I don't even see an easy solution to this problem, as {include}s are process _after_ the {extends} chain has been completely resolved.
To make this possible, the parser would either have to split into two steps, or a new tag {inject file="…"} had to be introduced, which could be processed even before {extends}. I didn't think about the ramifications of this propsal, yet.
At the moment I can only suggest merging whatever {block}s you might've {include}d into one of the files in your inheritance chain. Sorry. |
|
Back to top |
|
Mikaroz Smarty n00b
Joined: 06 Jun 2011 Posts: 3
|
Posted: Tue Jun 07, 2011 9:58 am Post subject: |
|
|
ok... thanks a lot globe |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Tue Jun 07, 2011 1:48 pm Post subject: |
|
|
Some additional explaination:
The included menu_top.tpl is parsed in the context of the parent template in which the surrounding block was extended. For that reason
{block} tags inside menu_top.tpl treated as parent block definitions, which was not your intention, but expected behaviour in other applications.
In general at nested {block} tags the inner blocks will always be interpreted as like a parent block even if they are loacted in a child template. |
|
Back to top |
|
rodneyrehm Administrator
Joined: 30 Mar 2007 Posts: 674 Location: Germany, border to Switzerland
|
Posted: Tue Jun 07, 2011 1:51 pm Post subject: |
|
|
Thinking about this makes my head spin. The side effects of {block}s within included templates are not obvious to the implementor. Shouldn't Smarty throw an exception if a {block} is {include}d? That is, as long the {include} does not contain it's own inheritance chain. |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Tue Jun 07, 2011 1:59 pm Post subject: |
|
|
globe that {block} tags inside that include is treated as parent {block}
is an intended, requested and used feature.
By definition template inheritance does move the content of the child block to parent context (in this case the {include} tag) by definition the behaviour is sort of logical as well. |
|
Back to top |
|
|