Smarty Templates - Return product info based on topic type

懵懂的女人 提交于 2019-12-25 04:50:47

问题


Im using the following code:

{foreach from=$entries key=i item=topic}
  {if $topic.topic_style == problem}
    <li>
      <a href="topic.php?id={$topic.id}">{$topic.title}</a>
    </li>
  {/if}
{/foreach}

Which returns the topics which are all 'problem's.

Its possible to tag a problem with a product, the system uses the Get Satisfaction API.

I want to return the product associated with this Topic, if there is a product associated with this Topic.

I have the following, which returns all products:

{foreach from=$products key=i item=product}
  {$product.name}
{/foreach}

Im wondering if anyone might be able to work out how I can combine these two pieces of code to return the product associated with this topic?


回答1:


why would you want to do this in smarty? it undermines the principle of using templates if you place so much php code in them i'd suggest you create an multidimensional array like $array[topic_key]['producs'] and loop through that with smarty



来源:https://stackoverflow.com/questions/3415970/smarty-templates-return-product-info-based-on-topic-type

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!