Hi, I have a controller file (for an email template extension) which I want to add a variable to the shortcodes. In the controller file, it has the following:
$productPars = array( 'special' => '{special_list}',
'bestseller' => '{bestseller_list}',
'new' => '{new_product_list}',
'selected' =>'{selected_products}');
What I would like is to add a variable (but it doesn't work this way):
$productPars = array( 'special' => '{special_list-$att}',
'bestseller' => '{bestseller_list-$att}',
'new' => '{new_product_list-$att}',
'selected' =>'{selected_products-$att}') ;
so that I could use shortcodes such as {bestseller_list-2} and in the controller use standard str_contains with switch statement etc to get the $att.
But what happens is the shortcode {bestseller_list-2} isn't accepted as a shortcode (the $att as a variable in this situation doesn't work) so in the template it contains the actual string "{bestseller_list-2}".
So I'm wondering what would be the best way to have a shortcode that is accepted as such with a variable in it?
ie {bestseller_list-2} {bestseller_list-3} {bestseller_list-1} etc all accepted as shortcodes without having to add each individually in an array.
Thanks
Just explode the shortcode by "_" and grab the last item of resulting array. Then do what you need with this number.
Professional OpenCart extensions, support and custom work.
Contact me via email or Skype by support@thekrotek.com
Thanks, could you please explain a little for me. At the moment, this doesn't work:
$productPars = array( 'special' => '{special_list-$att}',
'bestseller' => '{bestseller_list-$att}',
'new' => '{new_product_list-$att}',
'selected' =>'{selected_products-$att}') ;
The $att isn't considered a variable within the shortcode because if I use {new_product_list-2} on the email template, then do a switch statement, case '{new_product_list-2}' doesn't exist, which I'm assuming is because I can't use the variable in the shortcode ('new' => '{new_product_list-$att}',) Instead it is passed as a string on the email template so the email gets sent out showing the text "{new_product_list-2} "
$productPars = array( 'special' => '{special_list-$att}',
'bestseller' => '{bestseller_list-$att}',
'new' => '{new_product_list-$att}',
'selected' =>'{selected_products-$att}') ;
The $att isn't considered a variable within the shortcode because if I use {new_product_list-2} on the email template, then do a switch statement, case '{new_product_list-2}' doesn't exist, which I'm assuming is because I can't use the variable in the shortcode ('new' => '{new_product_list-$att}',) Instead it is passed as a string on the email template so the email gets sent out showing the text "{new_product_list-2} "
I ended up adding every variation of shortcode I would be using. Makes the code long and it's not what I wanted to do but it works.
You'd need to post the full code of the controller for anyone to give you a proper answer.
UK OpenCart Hosting | OpenCart Audits | OpenCart Support - please email info@antropy.co.uk
Guru Member
Who is online
Users browsing this forum: Google [Bot], niagato, Semrush [Bot] and 648 guests