using v-bind:href to bind an expression - vue.js

I am trying to bind an expression to a URL using v-bind of vue.js.
The binder expression will be a year of the folder and I want that expression to render in the links.
I am trying to get this to bind correctly.
Can someone see what I am improperly concatenating?
<a v-bind:href="'https://www.exmaple.com'+{{$route.params.year | year}}'+'&FolderCTID=0x012000507B97BC3FFDCE4D854E'">My Link</a>

I think you're looking for this:
<a v-bind:href="'https://www.example.com/' + ($route.params.year || year) + '&FolderCTID=0x012000507B97BC3FFDCE4D854E'">My Link</a>
Key changes:
|| instead of |. The latter is a bitwise operator.
Added parentheses to ensure the || is applied correctly. Otherwise the + operators will be applied first.
Ditched the {{ ... }}. They shouldn't appear within v-bind expressions.
Removed the extra ' after the }}.
Added an extra / after the .com.
This will give, for example:
https://www.example.com/2019&FolderCTID=0x012000507B97BC3FFDCE4D854E
It seems likely you'd want a ? in there somewhere but that wasn't included in the original code.
You haven't mentioned what year is but it appears that it's a default for when the year route param is missing. That's certainly what I've assumed.
You may also want to consider using a computed property for this as it's a little complicated for template logic.
Update:
Based on the comment it seems that you intended | to be a Vue filter.
A filter can only be applied to the end of the whole expression. You cannot use it in the middle. If you try to use it in the middle it will just be interpreted as the JavaScript | operator and not as a filter.
I suggest using a method instead. If you have a method called formatYear it can be called using formatYear($route.params.year) within your v-bind expression.

I added this into my hyperlink and it works like a charm! I am sure someone will need this
+ $options.filters.year($route.params.year) +'

Related

JMeter - get value from href

I am load testing an application that has a link that looks like this:
https://example.com/myapp/table?qid=1434e99d-5b7c-4e74-b64e-c24e9564514d&rsid=5c94ddc7-e2e4-4e69-8547-49572486f4d1
I need to get the dynamic value of the rsid so I can use it later in my script.
So far I have tried using the regex extractor and I am probably doing it wrong.
I have tried things like:
name = myvar
regular expression = rsid=(.*?) # didnt work
regular expression = <a href=".*?rsid=(.*?)"> # didnt work
Template = $1$
I have one extractor set up to get the csrf value and that one works as expected but that is also because the csrf value is in the page source.
The above link is NOT in the page source as far as I can see but it DOES show up when I inspect the link. I dont know if that is obfuscation or something else?
How can I extract the value of the rsid? Is the regular expression extractor the right one to use for this?
Should I be using something else?
Is it just a formula issue?
Thanks in advance.
Try something like:
rsid=[0-9A-Fa-f\-]{36}
the above regular expression should match a GUID-like structure and your rsid seems to be an instance of it.
Demo:
Also be aware of the Boundary Extractor, it's sufficient to specify "left" and "right" boundaries and it will extract everything in-between. In general coming up with "boundaries" is much easier than creating a regular expression, it's more readable and JMeter processes the Boundary Extractors much faster. More information: The Boundary Extractor vs. the Regular Expression Extractor in JMeter

How to pass key as variable to template in Bootstrap-Vue tables

There is a new syntax for scoped field slots in tables, see https://bootstrap-vue.js.org/docs/components/table#scoped-field-slots , which looks like
<template v-slot:cell(myColumn)="data">
...
where myColumn is interpreted as a string - key of field from fields to display in our table.
How can I use a variable instead of string? Let's say something like:
let myColumnName = "myColumn";
<template v-slot:cell(myColumnName)="data">
...
When using the new v-slot syntax of Vue 2.6.x, you can use the dynamic slot name syntax.
<template v-slot:[`cell(${myColumnName})`]="data">
or set the full slot name in a variable:
let fieldName = 'myColumn'
let slotName = `cell(${fiedlName})`
<template v-slot:[slotName]="data">
Anything between the square brackets is interpreted as a javascript expression. Just note that you cannot have spaces in the expression (HTML attribute names cannot have spaces).
The second example above is your best bet when using DOM templates. Just note that your variable names should probably be lower cased when using DOM templates (the browser lower cases everything before the = when it parses the template).
If using Single File Components (SFC), then you do not need to worry about letter casing.
To pass in variables you gotta add square brackets around the entire thing.
v-slot:[`cell(${myColumnName})`]="data"
or (whichever you prefer)
v-slot:['cell('+myColumnName+')']="data"

Vue.js interpolation values sum

There exist any way in Vue.js to make a sum between two interpolation values inside an html tag?
ex:
value1= 5
value2= 3
<span> {{value1}} + {{value2}}</span>
So I would like to know if its posible to obtain a third value rendered on the span tag adding the two values.
<span>{{value1 + value2}}</span>
I see no reason to manipulate data with operations on the template in this case.
The best (and simple) way, probably is to sum that values in your js code and render the result at template as another data property.
Although there is a Vue magic trick that allows you to made that.
It is called Computed Properties. Where you will be 'listening' some dependent data to create another data.
I totally recomend that you read Computed Properties documentation and see how it works
Here is the link:
https://v2.vuejs.org/v2/guide/computed.html
:)
Inside the {{}} you can run any JS really, so you should make a method that handles adding the 2 variables and inside that method it can check that both are numbers and handle converting strings if needed. Or you could try to turn this logic into a computed property.

Dynamic Freemarker variable name

I'm trying to set a variable with a dynamic name. This means the name for my new variable comes from another variable:
<#-- in real world I wouldn't declare this variables right here -
they would come from somewhere else -->
<#assign varName = "myVarName"/>
<#assign varValue = "myVarValue/>
<#... set the variable .../>
So that the value can be referenced as follows:
${myVarName} <#-- prints "myVarValue" -->
In a Java directive I would use
Environment#setVariable(String name, TemplateModel model)
to achieve this. But is there a possibility to achieve this with Freemarker directly?
I had a similar problem and Special Variable Reference page helped me:
vars: Expression .vars.foo returns the same variable as expression foo. It's useful if for some reasons you have to use square bracket syntax, since that works only for hash sub variables, so you need an artificial parent hash. For example, to read a top-level variable that has a strange name that would confuse FreeMarker, you can write .vars["A strange name!"]. Or, to access a top-level variable with dynamic name given with variable varName you can write .vars[varName]. Note that the hash returned by .vars does not support ?keys and ?values.
In my case I had to use only strings in my model. I had a bunch of names like Name1, Name2, ... Name10. To make a table of these names I used this code:
<#list 1..10 as x>
<#if .vars["Name" + x]??>
<tr>
<td align="center">${.vars["Name" + x]}</td>
</tr>
</#if>
</#list>
Use a hash. That is, use the name of the variable as the key of the hash.
There's no directive that assigns to a variable that has a dynamic name. But here's a hack to achieve that:
<#'<#assign ${varName} = varValue>'?interpret />
This isn't terribly fast though. It involves FTL parsing each time it's evaluated.
I guess you can do it like this:
${myVarName?eval} <#-- prints "myVarValue" -->
I found the answer from here, and it works to me.

How can i round a value in django template without using the filter

Is there any way that I can do some python math function in django template. Actually I need to round a variable value and I want to achieve this without using the filters.
For example like {{math.round(total)}}.
You can use floatformat to round of the value in django template.
{{ total|floatformat }}
If you want to perform more mathematical operations, you can try django-mathfilters. Or you could write your custom template tag and perform the operations in that template tag.
#arulmr gave the best way to fixed it, In my case I also needed include
{{ total|floatformat:0 }}
In order to round the value with zero decimal places, and
{{ total|floatformat:1 }}
To define the decimal places