How to define a variable with random values in Smarty - html

I need to assign a variable which will be used to create the id label for some html elements.
And it needs to be unique.
I tried
{assign var=unique_id value=`10|mt_rand:20`}
and
{math equation='rand(10,100)'}
But I don't know how to use the result
I don't have any other ideas

this is how you set and use a random value but that deoesn't mean it will be unique.
{assign var=unique_id value=10|mt_rand:20}
{$unique_id}
can you describe a bigger picture of what your doing ?

I wrote an little Smarty plugin some years ago: https://www.markus.zierhut.name/2010/05/21/php-mit-smarty-zufallszahl-erzeugen/
It's a bit easier to use than handling with mt_rand inside the assign-function. And it keeps compatible with the split of Model and View.

Related

How to select all elements with a specific name under every li node with the same structure?

I have a certain bunch of XPath locators that hold the elements I want to extract, and they have a similar structure:
/div/ul/li[1]/div/div[2]/a
/div/ul/li[2]/div/div[2]/a
/div/ul/li[3]/div/div[2]/a
...
They are actually simplified from Pixiv user page. Each /div/div[2]/a element has a title string, so they are actually artwork titles.
I want to use a single expression to fetch all the above a elements in an WebExtension called PageProbe. Although I've tried a bunch of methods, it just can't return the wanted result.
However, the following expression does return all the a elements, including the ones I don't need.
/div/
The following expression returns the a element under only the first li item.
/div/ul/li/div/div[2]/a
Sorry for not providing enough info earlier. Hope someone can help me out. Thanks.
According to the information you gave here you can simply use this xpath:
/div/ul/li/div/div[2]/a
however I'm quite sure it should be some better locator based on other attributes like class names etc.

Google Sheets - Fill multiple rows with different values

I am trying to enter multiple values to another column however It seems to be harder than I thought even that or I have no idea what I am doing, Is there an easier way to add different values to a different columns?
Example:
<span class="question" id="" onclick="expand('A101')" - On the ID="" Element I want to add different values like this: <span class="question" id="Q101" onclick="expand('A101')" however the Q/A 101 will go upto 327. (So from A101 to A327 and Q101 to Q327)
I have been looking for the past day on trying to do this without it pasting everything into one cell. I have even tried doing it Visual Studio but cannot seem to find a way other than manually entering them. As you can see from the image below, I am trying to add matching values in the Question and Answer elements. Same will go for the p tags because I want to add 1 answer to each element but they will need to be different. Do I have to do this manually?
Example Image of the code.
Here is my solution:
https://docs.google.com/spreadsheets/d/1Xvre3UPegHlZATzYn68lw11NYRv9sfg1v6Lfzzie5NU/copy
You need to cut it into pieces - parts that are used just as plain text and variables that change.
Then you combine cells using join() function and empty delimiter "".
Id this what you were looking for?

Angular concat 2 expressions

I got this:
{{columns.field}} and this {{resultado.!!!}}
and inside the !!! I need to put the {{columns.field}} I can't find a way to do it
I need to do it like this because I don't know the field in !!!, for that reason I got the {{columns.field}}, in this expression I picked up the value I need to put in !!!.
I'm sorry for my bad way of expressing myself
I tried something like this
Ready for top level Javascript ?
{{resultado[columns.field]}}

StringTemplate: HTML row formatting (odd/even)

I am new to StringTemplate template engine and want to use it for generating an html document with a table. I want to alter the style of the table rows depending on whether it is odd or even. I found a discussion on the stringtemplate-interest mailing list that describes the general approach ([stringtemplate-interest] Odd even row formatting).
But I have an additional requirement which breaks this general approach (I think). I want to render rows depending on the existence of a value. So I am working with a conditional expression $if(expr)$. My template looks like this.
delimiters „$“,“$“
htmlTable(valueA, valueB, valueC, valueD) ::= <<
<table>
<tr styleClass='odd'><td>$valueA$</td></tr>
$if(valueB)$
<tr><td>$valueB$</td></tr>
$endif$
<tr styleClass='odd'><td>$valueC$</td></tr>
<tr><td>$valueD$</td></tr>
</table>
>>
In the given template I can not use the hard coded styleClass attribute, because it would render the table wrong if the valueB parameter does not exist.
Is my requirement realizable with a template engine like StringTemplate, which focus on separation of model and view? Or is there too much model in the requirement as to implement it in the view? I know how to do it in other template engines (i. e. FreeMarker or Apache Velocity) or I might use some fancy CSS or javascript stuff but I would rather keep the model-view separation and use StringTemplates internal instruments.

HTML PHP SPAN ?? Span ID to display value based on the url?

www.mysite.com/?q=portraits#
I want a span within my menu to display the current section (ie. portraits)
I'm sure this is simple. Your help is much appreciated!
it's been a long time since i've used php, but the the variable you are referring to is what's known as a query string parameter, which is passed as a $_GET array in php. you can access the specific variable by using a string indexer of the array. in your markup:
<span><?php echo $_GET["q"]; ?></span>
You'll probably have to use javascript, if you're not working with PHP or something like that.
How to extract the get-query with javascript is explained here: How can I get query string values in JavaScript?
Then you can fork the result and add/remove content to/from the element you want to manipulate.