Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

too many shorthand attributes with {block ... append}

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Feature Requests
View previous topic :: View next topic  
Author Message
tacman1123
Smarty Rookie


Joined: 11 Mar 2004
Posts: 8
Location: Washington, DC

PostPosted: Wed Feb 23, 2011 12:22 pm    Post subject: too many shorthand attributes with {block ... append} Reply with quote

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
View user's profile Send private message AIM Address
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Wed Feb 23, 2011 2:05 pm    Post subject: Reply with quote

It looks like that you used "append" within the parent template.

"append" and "prepend" are only valid at the definition of child blocks.

See http://www.smarty.net/docs/en/language.function.block.tpl
Back to top
View user's profile Send private message
tacman1123
Smarty Rookie


Joined: 11 Mar 2004
Posts: 8
Location: Washington, DC

PostPosted: Wed Feb 23, 2011 8:16 pm    Post subject: Reply with quote

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
View user's profile Send private message AIM Address
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Wed Feb 23, 2011 9:04 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Mikaroz
Smarty n00b


Joined: 06 Jun 2011
Posts: 3

PostPosted: Mon Jun 06, 2011 7:41 pm    Post subject: Reply with quote

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
View user's profile Send private message
rodneyrehm
Administrator


Joined: 30 Mar 2007
Posts: 674
Location: Germany, border to Switzerland

PostPosted: Mon Jun 06, 2011 9:27 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Mikaroz
Smarty n00b


Joined: 06 Jun 2011
Posts: 3

PostPosted: Tue Jun 07, 2011 9:11 am    Post subject: Reply with quote

I understand the problem.
is there a way to do this? what is the best practice?
Back to top
View user's profile Send private message
rodneyrehm
Administrator


Joined: 30 Mar 2007
Posts: 674
Location: Germany, border to Switzerland

PostPosted: Tue Jun 07, 2011 9:20 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Mikaroz
Smarty n00b


Joined: 06 Jun 2011
Posts: 3

PostPosted: Tue Jun 07, 2011 9:58 am    Post subject: Reply with quote

ok... thanks a lot globe
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Tue Jun 07, 2011 1:48 pm    Post subject: Reply with quote

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
View user's profile Send private message
rodneyrehm
Administrator


Joined: 30 Mar 2007
Posts: 674
Location: Germany, border to Switzerland

PostPosted: Tue Jun 07, 2011 1:51 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Tue Jun 07, 2011 1:59 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Feature Requests All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP