I have one value that is tied to a flag that comes from a config file that I need to show in my soy template. It is either true or false.
If true, the value needs to be "x" (for example, but it is a string)
If false, the value needs to be "" (empty)
Notice that I cannot pass in the true or false value from my config. I also cannot omit the value on false, it has to supply an empty string.
I've tried various forms of if statements using let, but according to my interpretations of the docs, a value declared with let cannot be changed (which doesn't make sense)
This is basically what I need:
{if $inputValue.value == 'true'}
{let $myVar: ($someValueThatExistsInMyTemplate) /}
{else}
{let $myVar: '' /}
{/if}
Then I will use $myVar in my template. However, whenever I try that, I get this error:
Found references to data keys that are not declared in SoyDoc: [myVar]
What can I do!?
Got it working using the ternary operator:
{let $dataParent: ($item.preferences.accordionOnOff.value == 'true') ? ($item.name) : '' /}
Related
I have a custom DA that is called when JavaScript expression is document and I want it to execute only when a specific client-side condition is met.
So I set the client-side condition to javascript expression:
document.getElementById("myfield").options[status.selectedIndex].text != "Closed"
The issue is that myfield is no a page item, but rather an html control - a select box. So I have to use javascript expression instead of Item != Value.
Now when I run the page and attempt to perform the action that activates my DA, the condition is being checked and it errors out saying Cannot read property 'text' of undefined. How can I change my javaScript expression to get it to work?
In APEX, $x is a shorthand reference/pointer to document.getElementById, so you should be able to do this:
$x("myfield").options[$x("myfield").selectedIndex].text != "Closed"
When using JavaScript expression, if you need to do more than just a basic expression, you can use an Immediately Invoked Function Expression to break down the logic. Here's an example:
(function(){
var select = $x('page-item-id');
if (select.selectedIndex === -1) {
return false;
}
return select.options[select.selectedIndex].text != 'Closed';
})()
Alternatively, you could declare a function in the Function and Global Variable Declaration attribute of the page and then invoke it as an expression in the Condition of a DA.
I have a json data with some field value as null (eg: "location": null). I would need to check whether this field is null, and take some action.
I have tried using if [location] == 'null' { do something } but it fails, also I have tried with if [location] == 'nill' { do something }
Found some relative links that mentioned to check whether the field exist if [location] but this can't be used in my case.
Please help me to solve this, thanks in advance.
You will need to use the ruby filter to check if the field has a null value.
The following filter checks if the field is null and then, if true, adds a tag to the event.
ruby {
code => "if event.get('location').nil?; event.set('tags','null-value');end"
}
You can then use the tag normally in logstash to do what you want, for example
if "null-value" in [tags] { do something }
I am trying to build a module that will apply only in conditions when the requirements of the statement are satisfied. In this case if I specify the value for "var.enable_standbyinfra" that is true then the module will be created. I want to understand if I am approaching this type of method wrong or get on the right path
iam_instance_profile_standby = "${var.enable_standbyinfra == "true" ?
module.aem_disp_a_standby_iam.aws_iam_instance_profile_id : 0 }"
and further used in:
iam_instance_profile = "${local.iam_instance_profile_standby}"
The result is that I get an error when running terraform and the error is:
local.iam_instance_profile_standby: At column 3, line 1: true and false expression types must match; have type list and type int in:
${var.enable_standbyinfra == "true" ? module.aem_disp_a_standby_iam.aws_iam_instance_profile_id : 0 }
So the final result I want to get to is that if I specify that "var.enable_standbyinfra" is equal to true the resource is created. If set to "false" I want it to be skipped.
If I posted it wrong without a clear understanding please accept my excuses I am not a expert user in stackoverflow still learning
This argument should be a string, so:
var.enable_standbyinfra == "true" ?
module.aem_disp_a_standby_iam.aws_iam_instance_profile_id : ""
I'm trying to make a conditional statement based on whether a checkbox is checked or not. I've tried something like the following, but it always returns as true.
self.folderactive = QtGui.QCheckBox(self.folders)
self.folderactive.setGeometry(QtCore.QRect(50, 390, 71, 21))
self.folderactive.setObjectName(_fromUtf8("folderactive"))
if self.folderactive.isChecked:
folders.createDir('Desktop')
print "pass"
elif not self.folderactive.isChecked:
folders.deleteDir('Desktop')
print "nopass"
Is there a way to get a bool value of whether a checkbox is checked or not?
self.folderactive.isChecked isn't a boolean, it's a method - which, in a boolean context, will always evaluate to True. If you want the state of the checkbox, just invoke the method:
if self.folderactive.isChecked():
...
else:
...
x = self.folderactive.isChecked()
x will be True or Falseāa Boolean value.
(It's the brackets at the end that make the difference.)
In a handlebars template in Ember.js, I have blocks like the following:
{{content.some_attribute}}
{{content.some_other_attr}}
{{content.more_attr}}
Some of these attributes don't exist and I'm implementing them slowly.
Is there a way to get these templates to compile and either ignore the blocks that don't evaluate or better yet, replace them with a html element so they're easier to spot in the browser?
(the template is pretty large and it's being converted from ERB slowly,
Is there a way to get these templates to compile and either ignore the blocks that don't evaluate
Properties that don't exist are undefined, and don't get rendered at all. In other words {{thisDoesNotExist}} will simply be invisible -- it will compile just fine.
or better yet, replace them with a html element so they're easier to spot in the browser
As Cory said, you could use a helper for this that checks for undefined, using Ember.Handlebars.registerBoundHelper.
This seems like a perfect case for a handlebars helper. The helper could validate the value and return the value or the html that you desire.
The following code should be used very carefully, since it has not been tested within an application.
A possible solution to replace the possible undefined value in a template is to overwrite Ember.getPath, which is used to lookup the value of a path in a template, see http://jsfiddle.net/pangratz666/hKK8p/:
var getPath = Ember.getPath;
Ember.getPath = function(obj, path) {
var value = getPath(obj, path);
return (Ember.none(value) ? 'OMG %# is not defined!!'.fmt(path) : value);
};
If this code would be used temporarily in an application, I would also restrict the check for undefined values to a specific obj. So something along those lines:
App.objectWhichHasUndefinedProps = Ember.Object.create({
...
});
Ember.View.create({
templateName: 'templateWithAttributes',
objBinding: 'App.objectWhichHasUndefinedProps'
}).append();
var getPath = Ember.getPath;
Ember.getPath = function(obj, path) {
var value = getPath(obj, path);
if (obj === App.objectWhichHasUndefinedProps) {
return (Ember.none(value) ? 'OMG %# is not defined!!'.fmt(path) : value);
}
return value;
};