Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Smarty templates take variable and use in include string?

Tags:

php

smarty

I'm working with a shopping cart (CS-cart) that uses smarty templates. Products are associated with a brand. When the product page renders i'm able to get the brand ID.

I also have custom .tpl files such as brand1.tpl brand2.tpl where the number represents the row id from the db table.

If I have the brand ID in a variable, would someone show me an example of how to include the custom template and dynamically use the brand ID variable in place of the number in the file name being included. Something like below but I don't think $bid is a way to insert the variable. Any help is appreciated

Thanks

{include file='brand$bid.tpl'}

like image 304
Anagio Avatar asked Jan 17 '23 16:01

Anagio


1 Answers

try to use double quotes Example

{* body of template goes here, the $tpl_name variable
   is replaced with a value eg 'contact.tpl'
*}
{include file="$tpl_name.tpl"}
like image 60
Fivell Avatar answered Jan 25 '23 23:01

Fivell