3

I have some templates written with Smarty 3:

  1. A layout page
  2. An index page
  3. An include page

layout.tpl:

{block "css"}{/block}
{block "js"}{/block}
{block "content"}{/block}

index.tpl:

{extends "layout.tpl"}
{block "content"}
content text
{include "include.tpl"}
{/block}

include.tpl

{block "js" append}
include some extra js files for this included content
{/block}
include text

But I got a compiler exception:

Fatal error: Uncaught exception 'SmartyCompilerException' with message 'Syntax Error in template include.tpl {block "js" prepend} too many shorthand attributes

Is block append not available in an included template, even if it's included by the child template?

I think it'll be very helpful if I can use block append some way like this, or there might be other ways to do this? Thanks!

JochenJung
  • 7,183
  • 12
  • 64
  • 113
Dong
  • 911
  • 2
  • 9
  • 25

2 Answers2

2

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.

rodneyrehm
  • 13,442
  • 1
  • 40
  • 56
0

"too many shorthand attributes" is referring to the lack of attribute names in the statement:

{block "js" append}

Smarty gets confused because it is no longer clear what each attribute is referring to.

Instead, replace the shorthand attribute for "js" with the longhand version name="js" and you should be fine:

{block name="js" append}