Laravel having space output issue in blade file - laravel

I have Laravel code in Blade like this :
<span id="pk_dens" name="pk_dens" class="text-#if($productpages->pk_dens > 2.2 && $productpages->pk_dens < 3.3) success #else danger #endif">
{{$productpages->pk_dens}}%
</span>
So in class="text-#if($productpages->pk_dens > 2.2 && $productpages->pk_dens < 3.3) success #else danger #endif"
it will add space in class like text- danger and text- success so class not apply
so how can I avoid that spce in if else condition ?

Use ternary operator
<span id="pk_dens" name="pk_dens" class="text-{{ ($productpages->pk_dens > 2.2 && $productpages->pk_dens < 3.3) ? 'success' : 'danger' }}">
{{$productpages->pk_dens}}%
</span>
https://www.php.net/manual/en/language.operators.comparison.php#language.operators.comparison.ternary

I think you are missing here is ? in ternary syntax and to remove space just remove all white spaces from the span tag and make it in just one line.
<span id="pk_dens" name="pk_dens" class="text-{{ ($productpages->pk_dens > 2.2 && $productpages->pk_dens < 3.3) ? 'success' : 'danger' }}">{{$productpages->pk_dens}}%</span>

Related

Best practices to load and display a list of images in an hybrid app

I have a Ionic-1 app in which there's a large list that displays images (I use collection-repeat for this).
For now, I ship the images with the app. But the list evolves with time so my app gets the list from a server, then checks if there are new items, and use remote urls for new images.
The list is getting bigger (more tha 300 items), so managing this is quite heavy on the app. Moreover, shipping the images with the app is going to become impossible, because the .apk or .ipa are getting too big.
So I would like to use a better way to manage my images and also a better way to display them dynamically.
Is that possible to call the server images in my collection-repeat and to make it smooth and performant? Is that possible, that once an image has been called, it's saved in the local memory (maybe localStorage) so that the next time the list displayed it's faster ? If yes, how to do this ?
Is that the best way to manage a dynamical list? I would like to hear the best practice for this, for the best UX.
Here's my bit of code:
<div class="boardselection firstScreen" ng-if="transitionFinished">
<ion-item collection-repeat="item in prodataSelect | orderBy:data.sort | filter: data.selectBrand.brand:true | filter: data.selectName.name | filter: generalSearchFunc | filterObj:['brand','modelStrict']" item-width="25%" item-height="35%" item-render-buffer="16">
<a class="optionfuninit item-content" data-proid="{{item.id}}" on-tap="whatToDo(item.id,$event);" ng-class="item.fun == '0' ? 'aNormal' :( item.fun == '1' ? 'aSmallWave' : (item.fun == '2' ? 'aStepUp' : ''))">
<div class="listviewTrophy" ng-if="isWinning(item.id)">
<i class="icon ion-trophy"></i>
</div>
<i class="icon ion-female" ng-show="item.gender == 'female'"></i>
<!-- <p class="flex-caption" fittext fittext-min="10" fittext-max="15" ng-bind="item.modelStrict" >
{{item.modelStrict}}
</p> -->
<div class="listviewtexts flex-caption" ng-class="item.fun == '0' ? 'aNormal' :( item.fun == '1' ? 'aSmallWave' : (item.fun == '2' ? 'aStepUp' : ''))">
<span class="listviewtextsmodel">{{item.modelStrict}}</span>
</div>
<div class="imagebox">
<img class="imageoptionsmodel " ng-src="{{imagesUrls[item.imageName]}}"/>
</div>
</a>
</ion-item>
you can use ionic-cache-src (https://github.com/BenBBear/ionic-cache-src)
it will work like :
or
you can use $ImageCacheFactory to save it in cache,
docs here.

Prestashop 1.6 - Error price (schema.org)

please help me.
I have Prestashop 1.6.1.7 and when I testing product page in Google Structured Data Testing Tool displays an error notice.
Error notice picture
Error is in price, I do not know what to do.
I searched on Google, but all posts are old.
<!-- prices -->
<div>
<p class="our_price_display" itemprop="offers" itemscope itemtype="https://schema.org/Offer">{strip}
{if $product->quantity > 0}<link itemprop="availability" href="https://schema.org/InStock"/>{/if}
{if $priceDisplay >= 0 && $priceDisplay <= 2}
<span id="our_price_display" class="price" content="{$productPrice}">{convertPrice price=$productPrice|floatval}</span>
{if $tax_enabled && ((isset($display_tax_label) && $display_tax_label == 1) || !isset($display_tax_label))}
{if $priceDisplay == 1} {l s='tax excl.'}{else} {l s='tax incl.'}{/if}
{/if}
<meta itemprop="price" content="{$productPrice}" />
<meta itemprop="priceCurrency" content="{$currency->iso_code}" />
{hook h="displayProductPriceBlock" product=$product type="price"}
{/if}
{/strip}</p>
<p id="reduction_percent" {if $productPriceWithoutReduction <= 0 || !$product->specificPrice || $product->specificPrice.reduction_type != 'percentage'} style="display:none;"{/if}>{strip}
<span id="reduction_percent_display">
{if $product->specificPrice && $product->specificPrice.reduction_type == 'percentage'}-{$product->specificPrice.reduction*100}%{/if}
</span>
{/strip}</p>
<p id="reduction_amount" {if $productPriceWithoutReduction <= 0 || !$product->specificPrice || $product->specificPrice.reduction_type != 'amount' || $product->specificPrice.reduction|floatval ==0} style="display:none"{/if}>{strip}
<span id="reduction_amount_display">
{if $product->specificPrice && $product->specificPrice.reduction_type == 'amount' && $product->specificPrice.reduction|floatval !=0}
-{convertPrice price=$productPriceWithoutReduction|floatval-$productPrice|floatval}
{/if}
</span>
{/strip}</p>
<p id="old_price"{if (!$product->specificPrice || !$product->specificPrice.reduction)} class="hidden"{/if}>{strip}
{if $priceDisplay >= 0 && $priceDisplay <= 2}
{hook h="displayProductPriceBlock" product=$product type="old_price"}
<span id="old_price_display"><span class="price">{if $productPriceWithoutReduction > $productPrice}{convertPrice price=$productPriceWithoutReduction|floatval}{/if}</span>{if $productPriceWithoutReduction > $productPrice && $tax_enabled && $display_tax_label == 1} {if $priceDisplay == 1}{l s='tax excl.'}{else}{l s='tax incl.'}{/if}{/if}</span>
{/if}
{/strip}</p>
{if $priceDisplay == 2}
<br />
<span id="pretaxe_price">{strip}
<span id="pretaxe_price_display">{convertPrice price=$product->getPrice(false, $smarty.const.NULL)}</span> {l s='tax excl.'}
{/strip}</span>
{/if}
</div> <!-- end prices -->
Please help. Thanks

Prestashop 1.6. How to check if product isPack in .tpl?

I want to check in theme (front) product.tpl file (PS 1.6.1.4) if state if product is Standard product or Pack of existing products
{if $product_type == Product::PTYPE_PACK} not working....
I want to return boolean.
use:
{if $packItems|#count > 0}
an example of using you can find it in product.tpl in the theme folder.
used in this way:
{if $packItems|#count > 0}
<div class="short_description_pack">
<h3>{l s='Pack content'}</h3>
{foreach from=$packItems item=packItem}
<div class="pack_content">
{$packItem.pack_quantity} x {$packItem.name|escape:'html':'UTF-8'}
<p>{$packItem.description_short}</p>
</div>
{/foreach}
</div>
{/if}
in addition, there is in a products object:
$product->id_pack_product_attribute = null
$product->cache_is_pack = 0
for non-pack products

laravel Blade is their a neat solution to : Trying to get property of non-object

I have thins line of code
{{($user->company_privileges->level < 3 ? '' : ' disabled') }}
In my menu file
but when a user doesn't have a company I get the error
Trying to get property of non-object
Is their a neat way of dealing with this in one line?
Something like this comes to mind
{{ ($user->company_privileges === null) : '' ? ($user->company_privileges->level < 3 ? '' : ' disabled') ) }}
as the second if statement is only ran if the user has a company
I have the statement inside a tag aswell
<a class="{{($user->company_privileges->level < 3 ? '' : ' disabled') }}">
Why not something like
<a class="{{($user->company_privileges && $user->company_privileges->level < 3 ? '' : ' disabled') }}">
Essentially, what you need here is to know that null == false for bool comparison. Check out the PHP type comparisons table

Smarty check if date is between

i need check if smarty now date is equal or between my two dates.
If dates is the same months its work. But if:
Start = 19.01.2015 and
Stop = 1.02.2015 and
smarty now is 19.01.2015 it show no. Only if i change months it don't work
{if ($smarty.now|date_format:"%d.%m.%Y") >= ($value->getVariableValue('Start')) AND ($smarty.now|date_format:"%d.%m.%Y") <= ($value->getVariableValue('Stop'))}
yes
{else}
no
{/if}
try this i hope it will work :
Php file :
<?php
$start_date = "19.01.2015";
$end_date = "1.02.2015";
$smarty->assign('start', $start_date);
$smarty->assign('stop', $end_date);
$smarty->display("date.tpl");
?>
tpl file(date.tpl) :
<{if (($smarty.now|date_format:"%d.%m.%Y") >= ($start)) AND (($smarty.now|date_format:"%d.%m.%Y") <= ($stop)) }>
yes
{else}
no
{/if}

Resources