How can I assign smarty var that is only translated once and repeated in a template? - prestashop-1.6

I tried to use the following to assign a var and put translation to it but failed.
{assign var="figcaption" value="{l s='Free Migration or Installation' mod='twittercard'}"}
When I try to use the smarty var {$figcaption} now, I get an empty string.

{capture} is used to collect the output of the template between the tags into a variable instead of displaying it. Any content between {capture name='foo'} and {/capture} is collected into the variable specified in the name attribute.
{capture name="figcaption"}{l s="Free Migration or Installation" mod="twittercard"}{/capture}
{$smarty.capture.figcaption}
Use http://www.smarty.net/docs/en/language.function.capture.tpl

Related

Add types in the parameter table when generating document with Stardoc

We are trying to use Stardoc when generating documentation for our Bazel macros.
I can get a table generated with parameter descriptions when follow the instruction here:
Macro/Function documenatation.
But we would also like to add the parameter Type in the table.
According to DocstringUtils.java it seems like we shall write the type in parentheses after the parameter name but before colon, as this example:
another_parameter (unused, mutable): a parameter may be followed
by additional attributes in parenthese
I have seen that it's possible to add a rule template to the stardoc() rule (attribute: func_template).
I started to use an own copy of the default template to play around with: //stardoc:templates/markdown_tables/func.vm
If I have understood correctly it doesn't seem that the attributes that I add in paranthese is fetched.
And I don't think that I will be able to retreive that information by just updating the template.
So I think that it will need an update in the Stardoc code for this, correct?!
Is that something that is already planned?
If I'm not correct then I would appreciate information how I can retreive the value of the attribute.
Thanks!
Best Regards
Elisabeth

How do i read strings on separate lines

I'm trying to read strings on separate lines/space as title says.
I have a row on phpmyadmin which is:
I have a made a function to get the list value on Lua and the next step would be to read every name separately and thats what i can't figure it out.
Its possible to read every line separately and then add them to an array?
As for example
local names = {Noba, Detalle}
Solved:
local names = {}
for _, name in ipairs(getList():explode("\n"))
table.insert(names, name)
end

Thymeleaf replacing property variable with value from server side

I am trying to make UI by using Thymeleaf template engine. I have a property file, which contains list of messages for validations.
For example: I have a propery customer.collateral.allocated_amount=Entered amount is bigger than your available balance. Balance: {0}
Now this I wanna replace this {0} with value, which I get from server side from database. For example, I query from database and I get 500.50. And what I want to do now, is to display this propery with value. In this example, it would be: Entered amount is bigger than your available balance. Balance: 500.50
I tried to do this, but no luck:
<th class="right" th:inline="text">([[#customer.collateral.allocated_amount]], ${availableAmount})</th>
How could I do this?
Here are the steps you need to follow for a basic set-up to use Thymeleaf messages:
1) Let's assume you have a Thymeleaf template called customers.html.
2) Your properties file must therefore be called customers.properties, and it must be placed in the same directory as the customers.html template.
3) Let's assume your properties file contains this entry:
amountBiggerThanAvailable=Entered amount is bigger than your available balance. Balance: {0}
4) For the placeholder {0} I will assume you have a Java object called account which has a property called availableAmount and which you pass to Thymeleaf in the usual way (i.e. the same way you pass any other data to your Thymeleaf template). Of course, your version may be different.
Here, I will use a <div> for my example - but you can use whatever you want, of course:
5) Use the message in your template like this:
<div th:text="#{customers.amountBiggerThanAvailable(${account.availableAmount})}"></div>
Note that there is no actual content in the div (between the opening <div> and the closing </div>). All the Thymeleaf directives are attributes inside the opening <div>.
The above fragment will generate the following HTML in your web page:
<div>Entered amount is bigger than your available balance. Balance: 123.45</div>
Once you have got this far, there are various enhancement you can make. For example, you can also look into providing localized (translated) messages as described here.

How to get the last element inside array using VTL?

I am writing AWS AppSync resolver. Where I do need to get the last element in my array. AWS AppSync supports VTL language.
Example:
#set($items=["color", "taste", "shape"])
#set($result="shape")
I am using $array.size() but didn't work. I don't see any option in Utility Helpers.
.
#set($result=$item[$item.size()-1])
Thanks,
The solution is to make sure you are making the arithmetic operation inside -> set($result=$item[$item.size()-1]);
Set the array size into a separate variable and use another variable to get the last index.
#set($length=$facts.size())
#set($lastIndex = $length - 1)
#set($fact=$facts.get($lastIndex))

Trying to pass an argument/variable into an attribute in Rails

Imagine I have two models for a Greeting Card App: Template and Card. In creating a Card you specify the target's name, age, and which template you want to use (Card belongs_to template). The Template just has say title and body:text attributes.
I would obviously like there to be a placeholder for the target's name (and perhaps age) within the template body, because I want anyone to be able to create a Card, select the template, and see a Card with the chosen template using their target's name. Is there a way to pass in an argument to the body of the Template for the target's name? I have the Card and target info waiting in the controller but I don't know how to pass it the info since in creating the Template the body was typed into a form and is hard coded into the db as an attribute.
The only way around this I see would be to create a view for each Template instead of storing them in the database, or to create several 'chunks' of the template body, and insert the target's name in between. I'd like to figure this out the more efficient way. Thanks in advance!
If you did not want to do this as templates and truly want it store in the db then I would use javascript to replace keys embedded into the text.
This would also offload the search and replace to the client.
I found the easiest way to go about this ended up just using a designated keyword in the attribute and then replacing it in the controller using the ruby method .gsub!

Resources