Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change in extends behaviour around v3.1.28 #296

Closed
jonnybradley opened this issue Sep 24, 2016 · 9 comments
Closed

Change in extends behaviour around v3.1.28 #296

jonnybradley opened this issue Sep 24, 2016 · 9 comments

Comments

@jonnybradley
Copy link

Hi, excuse the long post

I work on the Tiki project and we have been unable to upgrade our version of Smarty since v3.1.21 for various reasons. I have an almost totally working implementation now with 3.1.30 but am stuck on one issue, which is in the way the extends resource seems to be working now.

We have many (100+) templates that start {extends 'layout_view.tpl'} which by default loads the complete page with head, body, menus etc, but when used via a service this needs to be overridden so it extends a simpler template, such as layouts/internal/layout_view.tpl which is done in the services broker using a line (in PHP) like:

$smarty->fetch("extends:layouts/internal/layout_view.tpl|list_friends.tpl");

Before 3.2.28, this overrides the {extends} tag in the template and uses this minimal one which only has the content block defined in it for dialogs etc.

In 3.1.28 and up this seems to be ignored and the tag is used instead of the added resource, and this can be proved by changing the extends tag to ask for a file that doesn't exists and i get a simple error message. Commenting out this line makes the php added resource be used as expected.

So is this no longer possible in Smarty >= 3.1.28? In which case i think we are stuck.

Or are we doing something wrong?

Thanks in advance,
jonny B

@artcs
Copy link

artcs commented Sep 24, 2016

from INHERITANCE_RELEASE_NOTES.txt:

Starting with 3.1.28 you can mix inheritance by extends resuorce with the {extends} tag.
A template called by extends resoure can extend a subtemple or chain buy the {extends} tag.

NOTE There is a BC break. If you used the extends resource {extends} tags have been ignored.

@jonnybradley
Copy link
Author

Thanks for the quick reply @artcs - so if i understand you correctly, in this minor update backwards compatibility (in this respect) has been abandoned, and it's no longer possible to replace a tag {extends} in a template with a resource extends when doing fetch in PHP.

Thanks for pointing out INHERITANCE_RELEASE_NOTES.txt which i hadn't spotted as I wasn't really expecting an overhaul of this significance in the 3.1 branch, somewhat surprised this wasn't left for 3.2 or even 4.x, anyway too late now i guess.

I tried using the $smarty->inheritance_merge_compiled_includes = false just in case but i see even that workaround has been removed in 3.1.30 (and i don't think had any bearing on the extends system anyway).

Any other suggestions would be greatly appreciated.

Sadly our project is now so completely dependant on being able to do this it looks like we will be stuck on an out of date version until we change or replace our templating system...

@artcs
Copy link

artcs commented Sep 25, 2016

Shouldn't be hard to fix. Your problem is, that the {extends} tag is no longer ignored, so you have to work around that. Instead of your $smarty->fetch('extends:... call, you could simply assign the parenttemplatepath to a variable and later use that in the {extends} tag.

@jonnybradley
Copy link
Author

Thanks, i guess that's all we're left with, although i reckon that's very far from not hard to fix with over 1000 template files... won't be happening for this release anyway.

@artcs
Copy link

artcs commented Sep 26, 2016

You could replace your {extends 'someparent.tpl'} with {extends $overloadparent|default:'someparent.tpl'}. So if $overloadparent is assigned, it will be used instead of the default. Could be done with a simple multi-file-grep oneliner for 1000 files in one go.

@jonnybradley
Copy link
Author

Good thinking @artcs - i think there's only a hundred or so with that extends tag in, so not such a biggie probably, would need some serious testing re the other 900 tpls though! ;)

Thanks for the tip, will try that later.

@uwetews
Copy link
Contributor

uwetews commented Sep 27, 2016

I will update the master branch with a flag to enable and disable the new feature.
If you used in the older mode the extends resource and extend tag Smarty did not do what the template code said. That could cause confusions. But I learned that really a couple of users run WEB sides this way.

uwetews added a commit that referenced this issue Sep 29, 2016
…ution of {extends} in templates called by extends resource

     #296
@uwetews
Copy link
Contributor

uwetews commented Sep 29, 2016

There is an update in the master branch.
With new property Smarty::$extends_recursion = false;
the new behavior can be disabled.
See also INHERITANCE_RELEASE_NOTES.txt

@uwetews uwetews closed this as completed Sep 29, 2016
uwetews added a commit that referenced this issue Sep 29, 2016
…ution of {extends} in templates called by extends resource

     #296
uwetews added a commit that referenced this issue Sep 30, 2016
…ution of {extends} in templates called by extends resource

     #296
@jonnybradley
Copy link
Author

Many thanks for adding that @uwetews - will look into it for our next release! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants