SMARTY template parser throwing error performing '{if}' on undefined index. #124

Closed
opened 2018-06-04 06:00:41 +00:00 by jamie · 16 comments
jamie commented 2018-06-04 06:00:41 +00:00 (Migrated from git.hazaar.io)

It is reported that the following error is generated:

ERROR #8 on line 16 in file /usr/local/share/project/vendor/hazaarlabs/hazaar-mvc/src/Text/Template.php(92) : eval()'d code ---------------------------------------- Undefined index: productCost ---------------------------------------- 

for the following template:

Dear {$recipient.fullName},

Thank you for your email.  Details are below:

Product Name: {$request.data.productName}
Product Code: {$request.data.productCode}
{if $request.data.productCost}Cost: {$request.data.productCost}{/if}

If you have any questions or require further assistance, please contact us on {$support.phone} or by emailing {$support.email}.

Best Regards,

Support Services

If the supplied params look like:

$params = array(
  'recipient' => array(
    'fullName' => 'Mr Joe Customer'
  ),
  'support' => array(
    'phone' => '02 1234 4567',
    'email' => 'support@example.com'
  ),
  'request' => array(
    'data' => array(
      'productName' => 'The Product Name',
      'productCode' => 'PROD001'
    )
  )
);
It is reported that the following error is generated: ``` ERROR #8 on line 16 in file /usr/local/share/project/vendor/hazaarlabs/hazaar-mvc/src/Text/Template.php(92) : eval()'d code ---------------------------------------- Undefined index: productCost ---------------------------------------- ``` for the following template: ``` Dear {$recipient.fullName}, Thank you for your email. Details are below: Product Name: {$request.data.productName} Product Code: {$request.data.productCode} {if $request.data.productCost}Cost: {$request.data.productCost}{/if} If you have any questions or require further assistance, please contact us on {$support.phone} or by emailing {$support.email}. Best Regards, Support Services ``` If the supplied params look like: ```php $params = array( 'recipient' => array( 'fullName' => 'Mr Joe Customer' ), 'support' => array( 'phone' => '02 1234 4567', 'email' => 'support@example.com' ), 'request' => array( 'data' => array( 'productName' => 'The Product Name', 'productCode' => 'PROD001' ) ) ); ```
jamie commented 2018-06-04 06:00:54 +00:00 (Migrated from git.hazaar.io)

changed the description

changed the description
jamie commented 2018-06-04 06:01:25 +00:00 (Migrated from git.hazaar.io)

changed the description

changed the description
jamie commented 2018-06-04 06:02:19 +00:00 (Migrated from git.hazaar.io)

changed the description

changed the description
jamie commented 2018-06-04 06:03:27 +00:00 (Migrated from git.hazaar.io)

changed the description

changed the description
jamie commented 2018-06-04 06:05:51 +00:00 (Migrated from git.hazaar.io)

changed title from SMARTY template parser throwing error performing '{if}' on {-missing-} index. to SMARTY template parser throwing error performing '{if}' on {+undefined+} index.

changed title from **SMARTY template parser throwing error performing '{if}' on {-missing-} index.** to **SMARTY template parser throwing error performing '{if}' on {+undefined+} index.**
jamie commented 2018-06-04 06:06:07 +00:00 (Migrated from git.hazaar.io)

changed title from SMARTY template parser throwing error performing {-'{if}'-} on undefined index. to SMARTY template parser throwing error performing {+{if}+} on undefined index.

changed title from **SMARTY template parser throwing error performing {-'{if}'-} on undefined index.** to **SMARTY template parser throwing error performing {+```{if}```+} on undefined index.**
jamie commented 2018-06-04 06:06:17 +00:00 (Migrated from git.hazaar.io)

changed title from SMARTY template parser throwing error performing {-{if}-} on undefined index. to SMARTY template parser throwing error performing {+'{if}'+} on undefined index.

changed title from **SMARTY template parser throwing error performing {-```{if}```-} on undefined index.** to **SMARTY template parser throwing error performing {+'{if}'+} on undefined index.**
jamie commented 2018-06-13 00:18:58 +00:00 (Migrated from git.hazaar.io)
created branch [`124-smarty-template-parser-throwing-error-performing-if-on-undefined-index`](https://git.hazaarlabs.com/hazaar/hazaar-mvc/compare/master...124-smarty-template-parser-throwing-error-performing-if-on-undefined-index)
jamie commented 2018-06-13 00:18:59 +00:00 (Migrated from git.hazaar.io)

mentioned in merge request !37

mentioned in merge request !37
jamie commented 2018-06-13 00:25:56 +00:00 (Migrated from git.hazaar.io)

Ok, I have simulated this in an application and I can not see the error. I think this could be because the template is being parsed inside a Warlock process and the error control is different there. I will see how I can replicate this.

Site note though. It appears that parameter tags that are adjacent to newlines is actually deleting the newline character(s). So in the above template, the output is:

Dear Jamie Carl,

Thank you for your email.  Details are below:

Product Name: My Test ProductProduct Code: ABCX123AU
If you have any questions or require further assistance, please contact us on  or by emailing support@apir.com.au.

Best Regards,

Support Services

Which is wrong. I'll look into this while I'm at it.

Ok, I have simulated this in an application and I can not see the error. I think this could be because the template is being parsed inside a Warlock process and the error control is different there. I will see how I can replicate this. Site note though. It appears that parameter tags that are adjacent to newlines is actually deleting the newline character(s). So in the above template, the output is: ``` Dear Jamie Carl, Thank you for your email. Details are below: Product Name: My Test ProductProduct Code: ABCX123AU If you have any questions or require further assistance, please contact us on or by emailing support@apir.com.au. Best Regards, Support Services ``` Which is wrong. I'll look into this while I'm at it.
jamie commented 2018-06-13 01:05:52 +00:00 (Migrated from git.hazaar.io)

I have managed to replicate the issue by removing the '@' sign from the line:

@$obj->render($params);

Also, I have fixed the newline issue in 53741fb77a

I have managed to replicate the issue by removing the '@' sign from the line: ```php @$obj->render($params); ``` Also, I have fixed the newline issue in 53741fb77ac887e0497cffc08303bb1a962f7a05
jamie commented 2018-06-13 01:16:21 +00:00 (Migrated from git.hazaar.io)

Figured it out. Basically I removed the above '@' sign from the overall render call and moved it to the individual sections that product executable code. Fortunately there were only 4 of these:

  • replaceVAR()
  • compileIF()
  • compileELSEIF()
  • compileURL()

That should be it. I have tested before the update and after and all code warnings are now gone so this should fix the issue in Warlock as well.

Figured it out. Basically I removed the above '@' sign from the overall render call and moved it to the individual sections that product executable code. Fortunately there were only 4 of these: * replaceVAR() * compileIF() * compileELSEIF() * compileURL() That should be it. I have tested before the update and after and all code warnings are now gone so this should fix the issue in Warlock as well.
jamie commented 2018-06-13 01:17:21 +00:00 (Migrated from git.hazaar.io)

closed via merge request !37

closed via merge request !37
jamie commented 2018-06-13 01:17:21 +00:00 (Migrated from git.hazaar.io)

closed via commit 50c29552f2

closed via commit 50c29552f2f2ffde6ab337fb3df89e2b251c5d12
jamie commented 2018-06-13 06:07:54 +00:00 (Migrated from git.hazaar.io)

mentioned in commit 50c29552f2

mentioned in commit 50c29552f2f2ffde6ab337fb3df89e2b251c5d12
jamie commented 2018-06-29 02:24:28 +00:00 (Migrated from git.hazaar.io)

changed milestone to %4

changed milestone to %4
jamie self-assigned this 2025-09-04 01:15:47 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: hazaar/framework#124
No description provided.