Do you like AbanteCart? Please rate AbanteCart or share your experience with other eCommerce entrepreneurs. Go to Softaculous rating page to add your rating or write a review

How to correctly add hook to $this->getHookVar('product_description_array')

Started by yonghan79, January 27, 2025, 07:21:54 PM

Previous topic - Next topic

yonghan79

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.

abolabo

hook var's value must be a string, not array.
Different extensions can add it's values and we use concatenation for that
"No one is useless in this world who lightens the burdens of another."
― Charles Dickens

yonghan79

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>

abolabo

"No one is useless in this world who lightens the burdens of another."
― Charles Dickens

abolabo

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)
"No one is useless in this world who lightens the burdens of another."
― Charles Dickens

Forum Rules Code of conduct
AbanteCart.com 2010 -