smarty cs-cart assign a link to a variable - smarty

I am learning smarty. I want to assign a link to a variable:
{assign var="book_link" value="`$smarty.capture.$name` nofilter"}
I want to use truncate to produce that book_link, so i use
<div class="title-book">{$book_link|truncate:50}</div>
But it did not work.

just change the double quotes from value and try this
{assign var="book_link" value=`$smarty.capture.$name` nofilter}

Related

Vue links are formatted weirdly

I am new to Vue js, Inertia and Laravel.
But I have gotten stuck and cannot figure out what the problem is even though I try searching google and looking at videos.
I have this code
<div v-for="(seed, index) in seeds" :key="index">
Id {{ seed.id }}
<inertia-link :href="'/fert/' + '{{ seed.id }}'">
Go to seed
</inertia-link>
</div>
And The first {{ seed.id }} outside of the links looks great, it shows the actual id.
However then {{ seed.id }} within the link formats, so the link shows this:
Id 1Go to seed
Why is it formatting inside the link but not outside? and how to I fix it?
Thanks in advance, and yes I am very noob. sorry
You shouldn't use curly braces in attribute's value.
Using :[attribute-name] already tells Vue that you gonna use some JS expressions in value
:href="'/fert/' + seed.id"
You shouldn't use curly braces within the link. A nicer way to concatenate vars with text is to use template literal ES6 with backticks
<inertia-link :href="`/fert/${seed.id}`">Go to seed</inertia-link>

How to use a vue array inside a quote?

I was trying to access a vue array inside a quote like this
<div v-for="category in categories">
Links
</div>
its doesnt seem to work. Then i tried taking the code out of the quote{{category.link}} this works fine . Is there any other way to do this?
Thanks
You must bind your attributes when they are from Vue variables.
<div v-for="category in categories">
<a :href="category.link">Link</a>
</div>
You can not pass an array of links as a value of the href attribute. You can pass one link at the same time, instead.
On the other hand, if we suppose category.link refers to one link only, then you can write this:
Link

Implementing the 360 magic spin in smarty

I can't integrate the 360 magic spin in smarty templates. While adding the following code
<a class="Magic360" href="assets/spin-images/Bar-360-01.jpg" data-magic360-options="filename: Bar-360-{col}.jpg;">
While adding the attribute of data-magic360-options with filename, the screen will goes blank.
I amusing smarty 2.x.
Smarty (PHP framework) counts all strings {..} like its own directives.
To avoid that, you should use the following code:
{literal}<a class="Magic360" href="assets/spin-images/Bar-360-01.jpg" data-magic360-options="filename: Bar-360-{col}.jpg;">{/literal}
or
<a class="Magic360" href="assets/spin-images/Bar-360-01.jpg" data-magic360-options="filename: Bar-360-{ldelim}col{rdelim}.jpg;">
Did you forget $ sign for col variable?
data-magic360-options="filename: Bar-360-{col}.jpg;"
Maybe you should use {$col}:
<a class="Magic360" href="assets/spin-images/Bar-360-01.jpg" data-magic360-options="filename: Bar-360-{$col}.jpg;">

Smarty - Display a Div Based on the Presence or Absence of a {CAPTURE} variable

I have defined a {CAPTURE} variable in Smarty using:
{capture name='websitediv'}
//code to generate some output to be captured.
{/capture}
and assigned the output to a template variable
{capture name='websitediv' assign='ws'}
I have condition set in my code whereby depending whether the above captured variable has a value or not, the contents of will be shown or hidden:
<div {if !isset($ws)} style="display:none" {/if}>
//else do something
</div>
Unfortunately, the last code does not work. No matter is the captured variable is available or not, the div remains displayed.
Just like a PHP variable, there is a difference between a Smarty variable being "unset", and it simply having a value which looks empty to a human.
In this case, your {capture} block is always processed, and always assigned to the variable, so the variable will always exist, and have some string content in it.
What you need to test is not its existence, but its content - is it an empty string, or, more likely, a string containing only the whitespace that sits between your Smarty tags.
Like in PHP, a completely empty string evaluates to false in a Smarty {if} statement, so you can say {if !$ws}...{/if} to detect that. But you want to ignore the whitespace, so what you probably want is {if !trim($ws)}...{/if}
<div style="{if !isset($ws)}display:none{/if}">
//else do something
</div>
With Smarty you've probably got bootstrap too, try this.
<div class="{if !isset($ws)}d-none{/if}">
//else do something
</div>

Eval Smarty Code inside a Smarty Template

is there a way to evaluate Smarty Code inside an existing Smarty template? For example, I may have the following construct:
smartyTemplate.tpl
<body>
<div id="dynamicPart">
{$valueFromDatabase}
</div>
</body>
Whereas the Smarty variable $valueFromDatabase contains another Smarty Template which I would like to be inserted in place of the variable and then evaluated as a template (with all the logic expressions in replacements neccessary).
without a custom resource, you could have just used an {include file="your/template.tpl"}. Or render the template from the database in code using $smarty->fetch("your/template.tpl") and assigning that to $valueFromDatabase.
{eval var=$valueFromDatabase}
will work

Resources