{include file=""} and {block name=""} problem

795 views
Skip to first unread message

matterk

unread,
Oct 8, 2009, 11:39:37 AM10/8/09
to Smarty Developers
When trying to override a block in a parent that was included using
{include} tag it fails. the original content of the block is
displayed, and the override is ignored. Given the below example, the
<!-- original content --> will be displayed.

header.tpl
======
{block name="cssInclude"}<!-- original content -->{/block}

base.tpl
======
{include file="header.tpl"}
<div>
....
</div>

index.tpl
======
{extend file="base.tpl"}

{block name="cssInclude"}
<!-- fails :( -->
{/block}

U.Tews

unread,
Oct 8, 2009, 12:37:27 PM10/8/09
to Smarty Developers
This is currently not supported. Will check next week if it could.

Cliff Chaney

unread,
Oct 10, 2009, 12:55:38 PM10/10/09
to Smarty Developers
If you're considering this addition, I'd like to propose making it a
bit more flexible.

Personally, I've never needed a block "override" as described. I
could always use {capture} to achieve the same effect. You have to
flip your logic around a bit, but it's doable.

For my projects, I found it more necessary to have blocks be able to
append to other blocks. Very common scenario is an included template
that adds UI components to a form or body that ALSO need <script>
elements added to the head. This is something you can't do with
{capture} - at least very easily.

So, in the above example, I would prefer that the {block
name="cssInclude"} in the extended template work by ADDING its output
to the {block} in the base tpl not replacing it. Or, alternatively, a
separate parm (i.e.at="top|bottom|replace") or entirely different
block tag would implement each ability (i.e. {extend block="xx"},
{replace block="xx"}, etc).

I have only come across one case where I wanted to add to the
beginning of the block (e.g. to add JavaScript to the top of a
<body>). So I'm less concerned about that scenario.

-C
> > {/block}- Hide quoted text -
>
> - Show quoted text -

U.Tews

unread,
Oct 10, 2009, 1:26:26 PM10/10/09
to Smarty Developers

Block append and prepend is already implemented. {block name=foo
append}. as soon as I am back from travelling I will do the
modification that it will work also with icluded templates. Regard uwe
On Oct 10, 6:55 pm, Cliff Chaney <cliffcha...@gmail.com> wrote:
> If you're considering this addition, I'd like to propose making it a
> bit more flexib
>

Cliff Chaney

unread,
Oct 11, 2009, 2:00:25 PM10/11/09
to Smarty Developers
Perfect. You rock. Sorry that I missed that. I'll try it out soon.

-C
> > > - Show quoted text -- Hide quoted text -

U.Tews

unread,
Oct 12, 2009, 10:41:07 AM10/12/09
to Smarty Developers
Overriding a block in a parent that was included using
{include} tag should work now with the latest SVN update.

Abalam

unread,
Oct 16, 2009, 10:17:07 AM10/16/09
to Smarty Developers
Hi,

I'm not sure it's the same problem but i have some problems with
recent SVN versions :

Not working :
{include file="{$smarty.get.table}.tpl.js"}
{include file="`$smarty.get.table`.tpl.js"}

Exception: Syntax Error in template "/home/inventaire/core/templates/
header.tpl.htm" on line 79 " " - Unexpected ".", expected one of: "`"
in /home/inventaire/core/libs/Smarty/sysplugins/
internal.templatecompilerbase.php on line 261

Is it a bug ?
It works with old versions of Smarty 3 SVN...

Thanks for reading,
Yann

U.Tews

unread,
Oct 16, 2009, 12:56:54 PM10/16/09
to Smarty Developers
The fix is in the SVN now

Abalam

unread,
Oct 17, 2009, 4:41:22 AM10/17/09
to Smarty Developers
Hi,

$num is the number 13 (not from Dr. House ^^)

This syntax generates an infinite loop :
{include file="smartip_example{$num}.tpl.htm"}

And this one works well :
{$o="smartip_example{$num}.tpl.htm"}
{include file=$o}

Thanks for reading,
Yann

U.Tews

unread,
Oct 17, 2009, 6:55:30 AM10/17/09
to Smarty Developers
Is fixed

Abalam

unread,
Oct 17, 2009, 7:06:15 AM10/17/09
to Smarty Developers
Okay thanks !

Frieder Kundel

unread,
Oct 17, 2009, 7:32:37 AM10/17/09
to smarty-d...@googlegroups.com
Hi Uwe,

that one broke includes for me.. i changed line35 back to $_smarty_tpl
and it works again.

regards,
frieder


2009/10/17 Abalam <ygaut...@gmail.com>:
--
Frieder Kundel

U.Tews

unread,
Oct 17, 2009, 7:49:32 AM10/17/09
to Smarty Developers
Okay thanks for the feedback. Must look into another solution.

On Oct 17, 1:32 pm, Frieder Kundel <frieder.kun...@gmail.com> wrote:
> Hi Uwe,
>
> that one broke includes for me.. i changed line35 back to $_smarty_tpl
> and it works again.
>
> regards,
> frieder
>
> 2009/10/17 Abalam <ygauthe...@gmail.com>:

U.Tews

unread,
Oct 17, 2009, 8:11:31 AM10/17/09
to Smarty Developers
Next try :-)

On Oct 17, 1:32 pm, Frieder Kundel <frieder.kun...@gmail.com> wrote:
> Hi Uwe,
>
> that one broke includes for me.. i changed line35 back to $_smarty_tpl
> and it works again.
>
> regards,
> frieder
>
> 2009/10/17 Abalam <ygauthe...@gmail.com>:

Frieder Kundel

unread,
Oct 17, 2009, 8:24:26 AM10/17/09
to smarty-d...@googlegroups.com
nope.. templates using {include file=$container.template} don't work with that.


2009/10/17 U.Tews <uwe....@googlemail.com>:
--
Frieder Kundel

U.Tews

unread,
Oct 17, 2009, 9:12:36 AM10/17/09
to Smarty Developers
Hope I got now all cases....

Danke für's testen....

On Oct 17, 2:24 pm, Frieder Kundel <frieder.kun...@gmail.com> wrote:
> nope.. templates using {include file=$container.template} don't work with that.
>
> 2009/10/17 U.Tews <uwe.t...@googlemail.com>:

Frieder Kundel

unread,
Oct 17, 2009, 9:37:14 AM10/17/09
to smarty-d...@googlegroups.com
looks fine for me.

you're welcome ;)

2009/10/17 U.Tews <uwe....@googlemail.com>:
--
Frieder Kundel

Abalam

unread,
Oct 17, 2009, 10:17:06 AM10/17/09
to Smarty Developers
Seems to work here too.

On 17 oct, 15:37, Frieder Kundel <frieder.kun...@gmail.com> wrote:
> looks fine for me.
>
> you're welcome ;)
>
> 2009/10/17 U.Tews <uwe.t...@googlemail.com>:

Abalam

unread,
Oct 19, 2009, 4:52:33 AM10/19/09
to Smarty Developers
Humm do you confirm that {include file="`$current_class-
>table`.tpl.js"} is not working ?

U.Tews

unread,
Oct 19, 2009, 9:49:22 AM10/19/09
to Smarty Developers
It does work at my place. What sort of problem do you have?

Abalam

unread,
Oct 19, 2009, 9:59:40 AM10/19/09
to Smarty Developers
I have a message :

Exception: Unable to load template "file : affaire.tpl.htm" in /home/
optima/core/libs/Smarty/sysplugins/internal.template.php on line 168

But i'm not sure about what line in my templates is...

Yann.

Abalam

unread,
Oct 19, 2009, 10:04:14 AM10/19/09
to Smarty Developers
I'm pretty confused about it, because it works fine with my old
version of Smarty 3, (from few weeks ago) i'm not sure : does it
search for "file : affaire.tpl.htm" or "affaire.tpl.htm" ?

On 19 oct, 15:49, "U.Tews" <uwe.t...@googlemail.com> wrote:

U.Tews

unread,
Oct 19, 2009, 10:17:30 AM10/19/09
to Smarty Developers
It does look for "affaire.tpl.htm". I added the resource type to the
error message. Maybe its confusing how I did it, but thats just the
message.

Abalam

unread,
Oct 19, 2009, 10:42:39 AM10/19/09
to Smarty Developers
I think i found the problem...

Do you throw an exception if you don't find EVERY templates, even if
it look like that :

{elseif ATF::$html->template_exists("`
$smarty.request.table`_select_all.tpl.htm")}
{include file="`$smarty.request.table`_select_all.tpl.htm"
parent_class=$current_class}

?

Note that all my framework is based on the template_exist() method...

Here i don't know why an exception is raised because Smarty will never
execute the include (it will not go in this elseif).

I think all my problems comes from this, once again it always works
with all previous smarty 3 (and 2) versions...

Thanks for reading.
Yann

Abalam

unread,
Oct 19, 2009, 11:01:51 AM10/19/09
to Smarty Developers
I understand the improvement, concerning pre-checks, but infortunately
i need Smarty to let me do the file exists checks, or only test
existence if the {include } is really evaluated...

Do you think it can be reverse like before on this ?

Or may be with a new attribute for {include dontprecheck=true} ?

Yann

U.Tews

unread,
Oct 19, 2009, 11:53:21 AM10/19/09
to Smarty Developers
Dear Yann

For better performance I had implemented a feature that the compiled
code of included subtemplates gets merged into the compiled code of
the main template. This feature is currently by default on.

You just identified two not covered situations:

1. Conditional includes based on the template_exist result
2. Sort of hidden variable template names when the variable part is
evaluated inside a double quoted string

The first one could be solved easily but not the second case.

I think we must use code merging only optional in save situations when
it's specified in the {include} tag for example like this:
{include file='my.tpl' mergecode}

For the time being you can disable the merging by setting $smarty-
>merge_compiled_includes = false;

Uwe

U.Tews

unread,
Oct 19, 2009, 4:38:17 PM10/19/09
to Smarty Developers
Yann

I found a general solution for teh reported problem. The fix is in the
SVN now.

Uwe
Message has been deleted

Yann GAUTHERON

unread,
Oct 20, 2009, 3:29:45 AM10/20/09
to smarty-d...@googlegroups.com
Thanks Uwe, it works even without any "merge_compiled_includes=false".

Thanks a lot,
Yann

U.Tews a écrit :

> Yann
>
> A general solution for your reported problem is in the SVN now.
>
> Uwe
>


> On Oct 19, 5:53 pm, "U.Tews" <uwe.t...@googlemail.com> wrote:
>

Abalam

unread,
Oct 20, 2009, 9:58:56 AM10/20/09
to Smarty Developers
Hi Uwe,

Are you sure for elseif condition ?


{if false}
NEVER PROCESSED
{elseif ATF::$html->template_exists("{$current_class->table}-
{$field}.tpl.htm")}
{include file="{$current_class->table}-{$field}.tpl.htm"} {* This
will never be processed ! *}
{/if}

But :
{if ATF::$html->template_exists("{$current_class->table}-
{$field}.tpl.htm")}
{include file="{$current_class->table}-{$field}.tpl.htm"} {* This
works ! *}
{/if}

Have an idea ?

Thanks for reading,
Yann

U.Tews

unread,
Oct 20, 2009, 11:15:52 AM10/20/09
to Smarty Developers
Yann

You are always good for the most complex special cases.

The {....} systax inside double qoutes has been introduced to merge
complex expressions or even the result of other Smarty (plugin) tags
into a doubled quoted string. This requires some code to get the
result into an internal temporary varibale upfront. I overlooked that
in case of an {else} or {elseif} tag this code is injected too early
(infront of the else condition). That's why it did fail. So it's a bug
which must be fixed.

Anyway as the {...} syntax was not intended for simple replacements of
a variable content. It compiles like a Smarty tag. For variable
replacements the Smarty backtick syntax has much better performance
and it does not show the bug.

So:
{if false}
NEVER PROCESSED
{elseif ATF::$html->template_exists("`$current_class->table`-`
$field`.tpl.htm")}
{include file="`$current_class->table`-`$field`}
{/if}

Will work correctly and has better performance.

Ofcause I will look into solving the original problem.

Thank's for all your testing and input.

Uwe

U.Tews

unread,
Oct 20, 2009, 1:13:25 PM10/20/09
to Smarty Developers
This bug is fixed in the SVN now.

Abalam

unread,
Oct 23, 2009, 3:40:53 AM10/23/09
to Smarty Developers
If works good.

Thanks a lot,
Yann
Reply all
Reply to author
Forward
0 new messages