How can remove first letters from a name in smarty? - foreach

This code find my first letter and show it. But how can remove it?
Like: From EDCstreet to street.
{foreach from=$elements item=street}
{if $street|substr:0:1 eq 'm'}
{$street}
{/if}
{/foreach}

You can use:
{foreach from=$elements item=street}
{if $street|substr:0:1 eq 'm'}
{$street|substr:1}
{/if}
{/foreach}
to display text without this first letter

Related

Accessing the name of a smarty variables

Hello i need some help with a basic question. This is my code:
{foreach $sArticle.attributes.core->toArray() as $attribute}
<tr class="product--properties-row">
<td class="product--properties-label is--bold">{$sArticle.attributes.name}{$sArticle.attributesName}</td>
<td class="product--properties-label is--bold">{$attribute}</td>
</tr>
{/foreach}
1.Question: How do I enter the attributes name? I mean the column name from the attribute in the database?
2.Question: I only want to loop with the foreach through columns with name="artikelattr_" any idea how this can be done?
Thanks
I adjusted my answer here: https://stackoverflow.com/a/71237355/7201069
How to get the name of the attribute.
To consider only certain attributes that starts with a specific string, just add an if in the loop:
{foreach $sArticle.attributes.core->toArray() as $attributeName => $attribute}
{if $attributeName|strpos:"artikelattr_" === 0}
{$attributeName|var_dump}
{$attribute|var_dump}
{/if}
{/foreach}
You can simply use nearly all PHP functions in Smarty.

Bitbucket custom column on repository list page

I am trying to write my first plugin for Bitbucket. I followed the tutorial to add a custom column to the branches list. It works great. After, I wanted to add a custom column to the repositories list with e.g. description or number of branches. However, when I check for web sections with:
http://localhost:7990/bitbucket/projects/PROJECT_1?web.sections
I do not see any on the repositories list page. Is it possible to add there some column?
Adam
it isn't supported by the Atlassian's layout
The project overview template contains a code
{if not $isEmptyProject}
{call bitbucket.internal.feature.repository.repositoryTable}
{param id: 'repositories-table' /}
{param repositoryPage: $repositoryPage /}
{param showPublicStatus: true /}
{/call}
{/if}
and the table row definition in the bitbucket.internal.feature.repository.repositoryTable template is
{template .repositoryRow private="true"}
<tr>
<td>
{if $showProject}
<span class="project-name">
{call bitbucket.internal.feature.project.avatar}
{param size: 'small' /}
{param project: $repository.project /}
{/call}
{$repository.project.name}
</span>
{/if}
<span class="repository-name">
{if not $showProject}
{call aui.icons.icon}
{param size: 'small' /}
{param useIconFont: true /}
{param iconFontSet: 'devtools' /}
{param icon: $repository.origin ? 'repository-forked' : 'repository' /}
{param accessibilityText: $repository.origin ? getText('bitbucket.web.repository.repository.forked') : getText('bitbucket.web.repository.repository')/}
{{param extraAttributes: $repository.origin ? ['title': getText('bitbucket.web.repository.is.a.fork.of', $repository.origin.project.name, $repository.origin.name)] : null/}}
{/call}
{/if}
{$repository.name}
</span>
{if $showPublicStatus}
{call bitbucket.internal.feature.repository.publicLozenge}
{param repository: $repository /}
{/call}
{/if}
</td>
</tr>
The only way is to replace somehow the .repositoryRow template, but I don't see a proper way to do it without hacking

Add Badge if product is on specific category on Prestashop

I need, for specific category, on single product page and category page and every other page, a custom badge. So if product is on category ID 14 display badge name "Premium" (of product is new or in sale must be appears also this badge unit "Premium").
I try to do this but not work (I put on products-list.tpl).
{assign var='premium' value=0}
{foreach Product::getProductCategories($smarty.get.id_product) as $category}
{if in_array($category, 14)}
{assign var='premium' value=1}
{/if}
{/foreach}
{if $associated==1}
<div class =" origine-GB "> </ div>
{/if}
Not work :(
First I must say this is quick hack and that proper way would be to make a module with custom hook maybe. But here is code you are aiming got.
In product-list.tpl add
{assign var='premium' value=0}
{if in_array('14', Product::getProductCategories($product.id_product))}
{assign var='premium' value=1}
{/if}
{if $premium==1}
<div class =" origine-GB "> </ div>
{/if}
And forproduct.tpl use
{assign var='premium' value=0}
{if in_array('14', Product::getProductCategories($product->id))}
{assign var='premium' value=1}
{/if}
{if $premium==1}
<div class =" origine-GB"> </ div>
{/if}
You were setting premium variable but use associated later.
Also in_array goes other way around in_array.

Separate link_to with comma

I want to separate this block with commas :
- game_publication.groups.each_with_index do |group, index|
= link_to store_group_path(current_store, group) do
%span= #groups.find(group).name.to_s + (index > 0 ? ', ' : '')
But for the moment it returns something like
<label>Groups :</label>
<a href="/66-store/groups/4594?locale=en">
<span>party hard</span>
</a>
<a href="/66-store/groups/5063?locale=en">
<span>b0m,</span>
</a>
<a href="/66-store/groups/5066?locale=en">
<span>test,</span>
</a>
</label>
It doesn't seems a situation where I can use any rails helpers.
I would like something like group1, group2, group3.
<label>Groups :</label>
<a href="/66-store/groups/4594?locale=en">
<span>party hard,</span>
</a>
<a href="/66-store/groups/5063?locale=en">
<span>b0m,</span>
</a>
<a href="/66-store/groups/5066?locale=en">
<span>test</span>
</a>
</label>
First, are you sure that you pasted here the exact code which gave the posted result? In your code, you have
(index > 0 ? '' : ',')
which means: Do not add a comma UNLESS we are on the first element. The result you posted had the comma the otherway round: It has a comma everywhere, EXCEPT for the first element. With other words: The code you posted, can't produce the output you posted.
Now for your problem: You want to add a comma on every element, except the last. This means that you need to know the highest (last) index value:
last_index = game_publication.groups.size - 1
With this, you can write your expression as
(index == last_index ? '' : ',')

Smarty - Difficult if else to make select options

I am having real trouble getting my head around this smarty else if.
For each
{foreach $values as $value}
{if $value = a}
do action
{elseif $value = b}
do action
{elseif $value = c}
do action
{/if}
{/foreach}
I only want to 'do action' once for the entire foreach. For any one iteration of the foreach a differnt condition(a b or c) might be = to $value
The real world example that I am working on is adding 'selected' to a drop down option.
<select>
{foreach $offices as $office}<!-- The if below is done so that the form is sticky, and when editing a post, it shows the post's current setting.-->
<option
{if $smarty.post.OfficeCode == $office.OfficeCode}
selected='selected'
{elseif $bulletin_array[0].OfficeCode == $office.OfficeCode}
selected='selected'
{elseif $office.OfficeCode == $UsersOffice}
selected='selected'
{/if}
title='{$office.Description}' value='{$office.OfficeCode}'>{$office.Title}
</option>
{/foreach}
</select>
the first if will be true if the form has been submited - to make the form sticky
the second part will be true the form is being pre-filled when editing the record - ie prefil the form with the current value
the third part will be true if the user is creating a new record, in which case set it to a default option that the user usually uses.
I need some way of only allowing selected to be added once.
I php I would have a variable outside the foreach which was set to true if selected was added. I would then check that variable before doing the if elseif
{if ($smarty.post.OfficeCode eq $office.OfficeCode)
or ($bulletin_array[0].OfficeCode eq $office.OfficeCode)
or ($office.OfficeCode eq $UsersOffice)}
selected='selected'
{/if}

Resources