i have inherited a project built in TurboGears that uses kid as the templating and wanted to find out what would be a better way to re-organize the following code:
<div py:if="style.style[0] == 'N' ">
<img src="${tg.config('cccorder.api_url')}/resources/logos/logoN.gif" alt="Clothing" /> </div>
<div py:if="style.style[0] == 'E' ">
<img src="${tg.config('cccorder.api_url')}/resources/logos/logoEP.gif" alt="Clothing" /> </div>
<div py:if="style.style[0] == 'S' ">
<img src="${tg.config('cccorder.api_url')}/resources/logos/logoSA.gif" alt="Clothing" />
</div>
the only variables here are the 'N', 'E' and 'S' and the actual images that change depending on the if
any advise much appreciated
It has been a while since I've worked with TurboGears so I'm a little rusty. One simple way to improve it would be to rename the files to logoN.gif, logoE.gif, logoS.gif, then you could consolidate the 7 lines into 3. Alternatively, you could adjust the value of style.style[0] to be N, EP, SA.
<div>
<img src="${tg.config('cccorder.api_url')}/resources/logos/logo${style.style[0]}.gif" alt="Clothing" />
</div>
Hope this helps!