Repeat string in apache velocity - velocity

I want to define a custom file template for my PhpStorm IDE and want to use #set directive to define a string variable based on $NAME
the name is foo/bar/baz I want to count / and create $RELATIVE_PATH variable ../../../
How can I create $RELATIVE_PATH based on $NAME?

Use the Java String.replaceAll() method:
#set($RELATIVE_PATH = "$NAME.replaceAll('[^/]+', '..')/")

Related

Ability to use environmental variables in Feature and Scenario Names

How to append Configuration variable in Feature name or in Scenario name. For Instance need to provide Info in reports based on environment run.
I saw there is an option available to add the Examples variable in Scenario outline name. on a similar note, do we have option to append Environment variable in Feature name?
Yes, in 1.0 onwards - if a variable exists in scope, it will be substituted in the Scenario name using the JS string interpolation syntax.
For example if your karate-config.js is like this:
function fn() {
return { test: 'foo' };
}
It means that the variable test will be available when the Scenario is processed. If not, note that the test will fail.
So if your feature is like this:
Feature:
Scenario: ${test}
* print test
You will see this in the report:
So it is up to you how you set up variables in the configuration init.

Global variables in Intellij templates

I am trying to create some variables similar to the predefined ones that come with the IntelliJ templating system. I am looking to create a variable called $MY_NAME_AND_EMAIL where I can define it once and then reference it in different templates. Is this possible?
I have tried creating an include called AuthorName.txt:
#set($MY_NAME_AND_EMAIL = "Name <email#example.com>")
Then, in one of my templates, I put the following line at the top:
#parse("AuthorName.txt")
Further down the file, I use ${MY_NAME_AND_EMAIL} in the header. However, when I create a new file base on that template, it still prompts me for the name and email field, even though I set it in an include file and added the #parse directive. What am I doing wrong?

Smarty Templates - Variable Inside Variable?

So I am currently doing a custom WHMCS template that uses the smarty template system. One of the calls is as follows:
{$customfield.input|replace:'>':'placeholder="Placeholder' >'}
Now this works in that it sets the placeholder with the text Placeholder. What I am trying to achieve is to get the following variable inside where the Placeholder text is:
{$customfield.name}
So I need something like the following:
{$customfield.input|replace:'>':'placeholder="{$customfield.name}" >'}
but that doesn't work.
Is this possible?
Correct way to do it
{$customfield.input|replace:'>':"placeholder='`$customfield.name`' >"}
Drop the braces around the second variable:
{$customfield.input|replace:'>':'placeholder="{$customfield.name|escape:html}" >'}

How to use Global Property name in my JSON input request using SoapUI?

I have a SoapUI project which contains around 60 plus services. Each service requires some input which will be changed for every execution. So I have created certain Global Properties and assign some values to that properties.
I have to use these properties values in my SoapUI request ( i.e. JSON Format request ).
If it is groovy script means, I will use like this.
String HTiC_Username = com.eviware.soapui.model.propertyexpansion.PropertyExpansionUtils.globalProperties['HTiC_Username'].value;
But, how to get the value of the Global Property in the request?
Hope you understand my question. Please provide proper guidance.
Thanks
To dynamically "expand" (i.e. substitute) the value of a property into a test step, the following syntax is used: ${#scope#propertyName}
...where 'scope' refers to the level at which the property has been defined (e.g. Global, Project, TestSuite, TestCase).
So to expand a property named username defined as a Global property, for example, the following code can be used directly within a Request Test Step (e.g within a JSON body, or header value, etc):
${#Global#username}
To access the same property value within a Groovy Test Step, you can use the following syntax:
context.expand('${#scope#propertyName}')
...as in the following example:
context.expand('${#Global#username}')
What we did was the following:
created a test data file to store all the specific input data for the different services (testdata.properties)
Example content of testdata.properties:
Billing_customerID=1234567
OtherService_paymentid=12121212
....
create a SoupUi global parameter (File/Preferences/Global properties): testdata_filepath=C:\...
For specific services we added a Properties test step. You can specify the "Load from" field to our new global parameter: ${#Global#testdata_filepath} Now you can use the Load button to load parameters.
Finally you can reference the parameter in your xml in the following format: ${Properties#Billing_customerID}
Example content of a service with parameter:
...
<BillingCustomerIdentification>
<BillingCustomerID>${#Properties#Billing_customerID}</BillingCustomerID>
</BillingCustomerIdentification>
...
To set up your projects in this manner also helps to automate service tests eg. using Hudson (see my previous SO answer).
If it is too heavy and automation is not a target, you can simply use ${#Global#someinputvariable} format in your xml ;-)

Opencart display one module conents into another module

I'm having custom footer module in my template. Also i'm using testimonial module in the position content bottom. I'm trying to display testimonial inside custom footer.
To do this i simply copied testimonial.tpl and testimonial.php contents and pasted into customfooter.tpl and customfooter.php
After this i'm getting errors stating
undefined variable and class name already assigned error
Did you know how to do this?
See this answer for how to do use a module in a separate modification/controller
opencart - How to manually display a module inside a template file?
You simply need to change from the common/home to your module's controller and view files
please define variable.
how can you define i will show you.
catalog > controller > header.php
for static variable
$this->load->language('common/header');
$data['text_home'] = $this->language->get('text_home');
// Where language file in assign this variable with different language foler
$data['text_home'] = $this->url->link('information/contact');
and you can tpl file in use this varible.
<?php echo $text_home; ?>
make sure 100% erorr has not facing
for dynamic variable