access outside variable in macro? - freemarker

how to access main namespace variable in macro?
I have a macro file called orderMacro.ftl, and import it in test.ftl like this:
<#import "path/orderMacro.ftl" as order/>
I also define a variable in test.ftl:
<#assign orderType="normal"/>
Now I access orderType variable in orderMacro using main.orderType, main means the namespace created for test.ftl(maybe I misunderstand this word).
it reports an error: Expression main is undefined

You need to write .main.orderType. Note the initial dot. It's the syntax for accessing "special variables", so that they can't clash with other variables.

Assign it using global
http://freemarker.org/docs/ref_directive_global.html
<#global orderType="normal"/>

Related

AWS Create Lambda script parameters output as parameter name, not value

I am running this Octopus community script for creating or updating a lambda function.
When we hard-code values for the parameters, the script works as advertised. However, when we define variables for use in the parameters, it always injects the name of the Octopus variable instead of the value.
Such that a variable named AWS_Dash_OrderOnline_Lambda_Function_Name is read as #{AWS_Dash_OrderOnline_Lambda_Function_Name} for the value instead of the actual variable value.
What's going on and what do I need to change?
Pertinent script code is below:
# Get the parameters.
$functionName = $OctopusParameters['FunctionName']
...
Write-Output $functionName
Output:
#{AWS_Dash_OrderOnline_Lambda_Function_Name}
You'll get the variable back as the value like this if a value cannot be determined. This could be because of a typo in the name, or it could be that there is no value for the variable that matches the scope of the current deployment.
For example, you may have a value for a variable called Foo defined for Prod and not for Dev. When you run a deployment into Dev you'll get #{Foo} but in Prod you'd get the actual value.
A technique I've used is to provide an unscoped value of something like "UnscopedFoo", then if you see that value you know you've got the name entered correctly and it's a scoping issue. If you don't then the name isn't entered correctly.
If you do not properly define your variable's scope, you will get the result as indicated in the question.
Define your scope, environment, roles, channels, etc properly and your variable values will import correctly.

using <#include> resoults in error: Can't find resource

I am implementing a freemarker code in an environment that stores the templates in an database.
for example
${bundle.key}
will display the value of the row with row_id = 'key'
However when I use include directive something doesn't work.
I have a template with a key GenF as follows
<#function PriceFormat Number>
<#return Number?string['0.0000']>
</#function>
if i run
${GenF.PriceFormat(1.568)}
I get the output
1.5680
as expected.
but when i run
<#include bundle.GenF>
${PriceFormat(1.568)}
I receive an error message:
Can't find resource for bundle ...structures.shared.localization.bl.MultiResourceBundle, key
do I use the include directive wrong, or is something was not defined correctly in the Data model by our programmers?
#include expects the name
(path, "file" name) of a template, not the template content itself. See: https://freemarker.apache.org/docs/ref_directive_include.html
What you seem to want is <#bundle.GenF?interpret />. Though note that the parsed template won't be cached that way, unlike when you invoke a template with #include. For #include to be able to resolve "bundle.GenF" as template name (or rather something like "bundle:/GenF", but it's up to you), you have to use a custom TemplateLoader (see Configuration.setTemplateLoader).
As far as you only need this for defining custom number formats, you may also want to consider using custom number formats (https://freemarker.apache.org/docs/pgui_config_custom_formats.html), like ${1.538?string.#bundle_GenF}.

xercesc NodeType not declared

I am developing an application to read XML files using xerces-c-3.1.1 using C++ on Netbeans 8.0.1.
I have a variable defined as type DOMNode* as follows
DOMNode* attribute=attributes->item(aIndex);
When I expand attribute in the debugger, it displays a function, getNodeType(), that returns a variable of type. However,when I add the code
NodeType value=attribute->getNodeType();
I get the error message
error: ‘NodeType’ was not declared in this scope
You could try xercesc::DOMNode::NodeType instead of writing NodeType.

Declare Jmeter variable from a property value

How can I declare a variable name by using the value of a property?
For example, I have the property propertyName with the value propertyValue. I want to declare a variable with the name propertyValue.
I've tried like ${${__P(variableName)}} but such constructions doesnt work.
You may need to evaluate the property name, using the ${__V()} function.
Thus, you'd probably end up with something like ${__V(${__P(propertyName)})} which would only declare a variable with a null value.
Basics on properties & command line:
if you need to pass variables through the command line, properties are indeed the correct choice.
The flag to set a property is -JpropertyName The function to read a property is ${__P(propertyName)}
For full details, see:
http://wiki.apache.org/jakarta-jmeter/JMeterFAQ#How_do_I_pass_parameters_into_my_Test_scripts.3F_I_want_to_be_able_to_use_the_same_script_to_test_with_different_numbers_of_threads_and_loops.2C_and_I_don.27t_want_to_have_to_change_the_script_each_time.
Give up using properties files, try using Variables From CSV plugin. It is pretty simple and robust way to have variables loaded from file.
Property files are great!!! For my requirement, I have created a simple config element for JMeter to read property files.
Please check here.
http://www.testautomationguru.com/jmeter-property-file-reader-a-custom-config-element.

VB: Accessing variable throughout the application

I have no of forms in VB 6. I want to access the value of one variable throughout the application.
What is the way to create global variable in VB 6.
EDIT: I want to create only one global variable. I am new to VB,So Please give me some code snippet
Thanks.
Create a module file (a file with the extension .bas) and in the (Declarations) section place something like the following in it:-
Public MyVariable As String
create a module and declare the variable there. Actually,you dont need to specify the Public keyword,things in module are by default treated as Public
Dim var1 as string

Resources