Developer forum

Forum » Templates » If...else statements and custom checkboxes

If...else statements and custom checkboxes


Reply

Is it possible to use the If...else statement together with custom checkboxes? If you have a textbox you can show different things depending on whether the field is filled or not. It is done like this:

 

<!--@If Defined(TagName)-->

    Show something

<!--@EndIf(TagName)-->

 

Is it possible to do the same with a custom checkbox? The problem is that you can't use the "If Defined" condition because a checkbox always is defined with the values True or False.

 

I was wondering if there exist other conditions than the "If Defined". I am thinking of something like:

 

<!--@If True(TagName)-->

    Show something

<!--@EndIf(TagName)-->

 

Or, maybe it is possible to check what the value of the field is?


Replies

 
Nicolai Høeg Pedersen
Reply
steffen@convince.dk wrote:

Is it possible to use the If...else statement together with custom checkboxes? If you have a textbox you can show different things depending on whether the field is filled or not. It is done like this:

 

<!--@If Defined(TagName)-->

    Show something

<!--@EndIf(TagName)-->

 

Is it possible to do the same with a custom checkbox? The problem is that you can't use the "If Defined" condition because a checkbox always is defined with the values True or False.

 

I was wondering if there exist other conditions than the "If Defined". I am thinking of something like:

 

<!--@If True(TagName)-->

    Show something

<!--@EndIf(TagName)-->

 

Or, maybe it is possible to check what the value of the field is?


 

I'm not sure I understand with custom checkboxes - one you made in your own module maybe?

 

Only script thing that exists is If defined and If Not Defined. Usually a checkbox would return whatever value it is given if checked and an empty string if it is not checked. So <input type=checkbox value=true> would return "true" in the request if checked and "" (empty string) when not checked. So you should be able to use If not Defined instead of If defined.

 

Of course, if you put the value to a true/false or bit field in a database first, it will come back as true/false.

 

Ooh - now I get it. You are in ecommerce? Then there is no way out of your pain except Javascript...

 

PS: We will release xslt based templates with the next update package giving full scripting capabilities to the template system. We find this better than inventing our own. Will be released around september or MAYBE with the june update.

 
Reply
NP wrote:
steffen@convince.dk wrote:

Is it possible to use the If...else statement together with custom checkboxes? If you have a textbox you can show different things depending on whether the field is filled or not. It is done like this:

 

<!--@If Defined(TagName)-->

    Show something

<!--@EndIf(TagName)-->

 

Is it possible to do the same with a custom checkbox? The problem is that you can't use the "If Defined" condition because a checkbox always is defined with the values True or False.

 

I was wondering if there exist other conditions than the "If Defined". I am thinking of something like:

 

<!--@If True(TagName)-->

    Show something

<!--@EndIf(TagName)-->

 

Or, maybe it is possible to check what the value of the field is?


 

I'm not sure I understand with custom checkboxes - one you made in your own module maybe?

 

Only script thing that exists is If defined and If Not Defined. Usually a checkbox would return whatever value it is given if checked and an empty string if it is not checked. So <input type=checkbox value=true> would return "true" in the request if checked and "" (empty string) when not checked. So you should be able to use If not Defined instead of If defined.

 

Of course, if you put the value to a true/false or bit field in a database first, it will come back as true/false.

 

Ooh - now I get it. You are in ecommerce? Then there is no way out of your pain except Javascript...

 

PS: We will release xslt based templates with the next update package giving full scripting capabilities to the template system. We find this better than inventing our own. Will be released around september or MAYBE with the june update.

 

I'm in the HR module and I have created a custom field that is a checkbox. The thing is that I only want an employee to be displayed if the checkbox is checked. But it is not possible to define values for the checkbox, only name and system name, so by default the checkbox returns only true or false.
 

I have already fixed the problem with Javascript, but this only hides the employee. His informations are still in the source code of the page.

 

You must be logged in to post in the forum