-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Bug: [Parser] Cascading Data causes ErrorException #7096
Comments
Thank you for reporting. |
@kenjis the example under 'Nested substitutions' has the same issue using the same data format for $parser = \Config\Services::parser();
$data = [
'blog_title' => 'My Blog Title',
'blog_heading' => 'My Blog Heading',
'blog_entry' => [
'title' => 'Title 1',
'body' => 'Body 1',
],
];
return $parser->setData($data)->renderString("<h1>{blog_title} - {blog_heading}</h1>
{blog_entry}
<div>
<h2>{title}</h2>
<p>{body}</p>
</div>
{/blog_entry}"); In both cases, I think adding support for a single object of array/value pairs will allow this simple syntax to be parsed correctly without changing the documentation examples. I've sent a PR to implement this fix: #7109 |
@fraigo I fixed the sample code in my PR.
|
PHP Version
7.4
CodeIgniter4 Version
4.2.11
CodeIgniter4 Installation Method
Composer (using
codeigniter4/appstarter
)Which operating systems have you tested for this bug?
macOS, Linux
Which server did you use?
apache
Database
No response
What happened?
The following code example extracted from https://codeigniter4.github.io/userguide/outgoing/view_parser.html#cascading-data triggers an exception
Parser::parsePair(string $variable, array $data, string $template)
expects an list of items with key/value pairs for the$data
parameter. In this case$data
is['city' => 'Red City', 'planet' => 'Mars']
.It works fine with loop substitutions like in this example https://codeigniter4.github.io/userguide/outgoing/view_parser.html#loop-substitutions
It does not work with the above example or in any 'nested' substitution like this example https://codeigniter4.github.io/userguide/outgoing/view_parser.html#nested-substitutions
Steps to Reproduce
Run this code from a controller:
Expected Output
George lives in Red City on Mars.
Anything else?
Backtrace:
SYSTEMPATH/View/Parser.php : 318 — CodeIgniter\Debug\Exceptions->errorHandler
SYSTEMPATH/View/Parser.php : 242 — CodeIgniter\View\Parser->parsePair
Arguments
The text was updated successfully, but these errors were encountered: