4

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'}

4
  • I feel pretty sure the Smarty documentation will cover this scenario. It's usually a good practice to check the API docs for whatever library you're using before posting a Q on SO. A-holes like me might flame/downvote you for it ;) Commented Jan 25, 2012 at 23:05
  • I'm a firm believer in RTFM myself. I pieced together other smarty code with cs-cart's loops and did what I could with this mod but needed the help. You know what they say about opinions, they're like A-holes everyone's got'em Commented Jan 25, 2012 at 23:15
  • Gotchya. It did seem there was some thought and effort behind the question, which stayed my hand from the righteous downvote of justice. More of a PSA, really :) Commented Jan 25, 2012 at 23:17
  • Thanks Daniel, you did the right thing. PSA's are always needed Commented Jan 25, 2012 at 23:23

2 Answers 2

5

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"}
Sign up to request clarification or add additional context in comments.

Comments

4

Look into documentation: http://www.smarty.net/docs/en/language.syntax.quotes.tpl Example 3.6 covers your question.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.