smarty-php / smarty-php/smarty

append-option in capture not working with included templates anymore

Open
#1,062 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
2.3k
Forks
709
PR merge metrics
No merged PRs in 30d

Description

We're running a complex structure of template includes and there we use {capture} with "assign".
To keep the array in the scope of the parent template we pre-defined the variable on top of the template that includes the other templates.
That worked so far with v4.5.3, but not anymore with v5.4.0+. I think also it never worked in v5 as the file was not changed since creation.

As I saw in v.4.5.3 there was some code for scope handling in the append() function - but that's not there anymore in v5.4.
For testing I added the global scope to the $this->assign() in src/Data.php:189 and it worked again.

Also with a little bit more debugging the already existing value from the main template gets fetched and the new capture-append-content is added but it's saved with SCOPE_LOCAL (as default) and so there is added a new variable for the included template.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Inspect src/Data.php around line 189 and the append() and assign() paths, starting with how included templates resolve scope. Reproduce the v4.5.3 versus v5.4.0 behavior with a parent template, included templates, and capture append; done means the appended value remains in the parent template's predefined variable rather than creating a local variable.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
web-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.