-
-
Save twokul/3332270 to your computer and use it in GitHub Desktop.
exploring inline decision-logic in templates
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- here's the PHP'ish way of making inline decisions while constructing HTML markup --> | |
<select name="foobar"> | |
<option value="bam" <?=($foobar==="bam"?"selected":"")?>>Bam</option> | |
<option value="baz" <?=($foobar==="baz"?"selected":"")?>>Baz</option> | |
</select> | |
<input type="radio" name="foobar" value="bam" <?=($foobar==="bam"?"checked":"")?>> Bam | |
<input type="radio" name="foobar" value="baz" <?=($foobar==="baz"?"checked":"")?>> Baz |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- here's another PHP'ish approach using parameterized function calling --> | |
<?php | |
function selected($val,$test){ return ($val===$test?"selected":""); } | |
function checked($val,$test){ return ($val===$test?"checked":""); } | |
?> | |
<select name="foobar"> | |
<option value="bam" <?=selected($foobar,"bam")?>>Bam</option> | |
<option value="baz" <?=selected($foobar,"baz")?>>Baz</option> | |
</select> | |
<input type="radio" name="foobar" value="bam" <?=checked($foobar,"bam")?>> Bam | |
<input type="radio" name="foobar" value="baz" <?=checked($foobar,"baz")?>> Baz |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment