This is a part from Magento_Checkout/web/template/minicart/item/default.phtml file:

<dl class="product options list">
    <!-- ko foreach: { data: options, as: 'option' } -->
    <dt class="label aaa" data-bind="i18n: option.label"></dt>
    <dd class="values">
        <!-- ko if: Array.isArray(option.value) -->
            <span data-bind="html: option.value.join('<br>')"></span>
        <!-- /ko -->
        <!-- ko ifnot: Array.isArray(option.value) -->
            <span data-bind="html: option.value"></span>
        <!-- /ko -->
    <!-- /ko -->

Adding the following line inside that foreach loop, breaks content.

<span data-bind="html: custom_variable_data"></span>

But the same line (span) works ok anywhere else in the code file. Am I missing some kind of syntax rule here?

  • Where you set your custom property custom_variable_data? – Siarhey Uchukhlebau Feb 19 at 13:30

When ko render specified template it using current context, which is item in your case. If current item has no property custom_variable_data you will se an error like that one:

error exmaple

If you want to call a parent property (minicart property) you can access it using the $parent context like this:

<span data-bind="html: $parent.custom_variable_data"></span>

but parent must have that property.

PS: syntax is right

| improve this answer | |
  • $parent did the trick – zekia Feb 19 at 13:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.