AbanteCart Community

AbanteCart Development => Development Help Needed => Topic started by: yonghan79 on January 27, 2025, 07:21:54 PM

Title: How to correctly add hook to $this->getHookVar('product_description_array')
Post by: yonghan79 on January 27, 2025, 07:21:54 PM
Hi core devs,

I'm found this hook "$this->getHookVar('product_description_array')" in the product.tpl file.

I have tried to add array like this:


$tabs['Test'] = [
       'title' => $view->fetch('pages/test/test_tab.tpl'),
       'html' => $view->fetch('pages/test/test_content.tpl')
];
$that->view->addHookVar('product_description_array',$tabs);


It's not working.

I tried to debug in the tpl file and found out that the variable is set as a string contains 'array', not a real array.
Title: Re: How to correctly add hook to $this->getHookVar('product_description_array')
Post by: abolabo on January 28, 2025, 03:39:19 AM
hook var's value must be a string, not array.
Different extensions can add it's values and we use concatenation for that
Title: Re: How to correctly add hook to $this->getHookVar('product_description_array')
Post by: yonghan79 on January 28, 2025, 03:51:26 AM
This is what is in products.tpl file:

$hookVarArray = $this->getHookVar('product_description_array');
                if( $hookVarArray ){
                foreach($hookVarArray as $key=>$hkVar){ ?>
                <div class="accordion-item">
                    <h2 class="accordion-header" id="heading<?php echo $key?>>">
                        <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapse<?php echo $key?>"
                                aria-expanded="true" aria-controls="collapse<?php echo $key?>">
                            <?php echo $hkVar['title']; ?>
                        </button>
                    </h2>
                    <div id="collapse<?php echo $key?>" class="accordion-collapse collapse" aria-labelledby="heading<?php echo $key?>" data-bs-parent="#productDetailsAccordion">
                        <div class="accordion-body">
                            <?php echo $hkVar['html']; ?>
                        </div>
                    </div>
                </div>
Title: Re: How to correctly add hook to $this->getHookVar('product_description_array')
Post by: abolabo on January 28, 2025, 06:32:01 AM
$hookVarArray is a string, not array!
Title: Re: How to correctly add hook to $this->getHookVar('product_description_array')
Post by: abolabo on January 28, 2025, 06:33:49 AM
if you want to pass an array use $that->view->assign('your_tpl_variable_name', $someArray); inside your hook file where $that = $this->baseObject; (controller instance)