phptaltemplate-tal

phptal - using defined variables in php conditions


I would like to use defined variables by phptal within php conditions as follows :

...
<tal:block define="className php: (photoIndex < 10) ? 'thumbItem thumbColumn1' : ( (photoIndex == 10) ? 'thumbItem thumbColumn2 thumbReset' : 'thumbItem thumbColumn2' )">
<tal:block define="defaultVal photo/isDefault">
<tal:block define="classNameWithIndex php: defaultVal ? '${className} modalMegaPhotoSelect' : '${className}'">
<li tal:attributes="class classNameWithIndex">
...

Here my output is "${className} modalMegaPhotoSelect" where as I expect it to be as "thumbItem thumbColumn1 modalMegaPhotoSelect" - the exact expectation is irrelevant the idea is the className should be percieved as a variable -

Thanks for your time.


Solution

  • Instead of '${className}' simply use className.

    Instead of '${className} modalMegaPhotoSelect' use className . ' modalMegaPhotoSelect' (with spaces around .).