Hello everybody,
It’s been ages since I had some free time, so now that I have, I decided to go deeper into MODx, which I hadn’t touch in months.
I’m trying to create a unique template, which could be either :
- single column
- 2 columns
- 3 columns
As I’d prefer not to have 3 different templates for this, I created 3 TVs :
- "nbCols" : dropdown list to select the class of my main container
- "Col2" : textarea for column 2 content
- "Col3" : textarea for column 3 content
What I’d like to achieve, in my template is this type of code :
<?php
$ColsType = $modx->getTemplateVar('nbCols', "", $modx->documentIdentifier);
?>
<div class="[*nbCols*]">
<div class="col1">
[*content*]
</div>
<?php if ($ColsType['value']<>'onecol') {echo '<div class="col2">
[*Col2*]
</div>'}?>
<?php if ($ColsType['value']=='threecol') {echo '<div class="col3">
[*Col3*]
</div>'}?>
</div>
I precise that I don’t know PHP language, even if I can read it, so I’m not sure that the syntax is correct or relevant... (I’ve seen a simplier way to tell "if(test);true;false" but...

)
The thing is, even the first code line (calling the API function) doesn’t work as it is displayed on my screen...
So a first question would be :
is it possible to call API functions in templates, or do I have to create a special snippet for it?
Also, I’ve figured that there would be other ways to do that, like telling : If [*Col2*] is empty, don’t display it
(but I’d still need my class TV for the CSS to work)
But my second point will be :
could I do that with PHx, and will it be better according to you?
Something like that (I didn’t test) :
[+phx:if=`[*nbCols*]`:is=`twocol`:then=`<div class="col2">[*Col2*]</div>`+]
I’d really appreciate if somebody could advise me and correct the code I try to implement, I’ve spent too much time on that problem, and I’d like to move on to other issues...
Thank you in advance.
Regards,
Greg