I use woocommerce.php in WordPress, it contains the woocommerce_content(); line to display WooCommerce informations (https://docs.woocommerce.com/document/woocommerce-theme-developer-handbook/). I like to add a custom header background image to this page. Basically I generate a Meta Box, which has an input field to upload the image. I retrieve the informations like:
echo get_post_meta( get_the_ID(), header_background_image', true );
and display it like so:
$headerBackground = get_post_meta( get_the_ID(), 'header_background_image', true );
<header class="header" style="background-image: url('<?php echo $headerBackground; ?>')">
This code works well all pages but WooCommerce and I can't figure out why. Do you have any idea?
Related
I'm using OctoberCMS with Laravel.
I use File Upload / Media Finder to attach an image. I'm trying to add thumbnails to the Backend Model columns.
I tried following these guides:
https://octobercms.com/forum/post/how-to-display-pictures-in-backend-lists
https://octobercms.com/docs/database/attachments
File Upload
Columns Thumbnail
Model
I have in my Model Catalog.php
public $attachOne = [
'photo' => 'System\Models\File'
];
In columns.yamal
Field photo set to partial and added path.
In the partial _photo.htm I have
<?php echo $this->photo->getThumb(100, 100, ['mode' => 'crop']); ?>
Error
I get Error: Call to a member function getThumb() on null.
If I use <img src="" /> in the partial it will display an empty image in the columns, but I don't know what php to put as the src.
According to column widget when you are using partial it will pass $record variable corresponding to that row, [ do not use $this there ]
means for that row $record will point to current record so you can use $record
your _photo.htm should be like this
<img src="<?php echo $record->photo->getThumb(100, 100, ['mode' => 'crop']); ?>" />
<!-- OR -->
<img src="<?= $record->photo->getThumb(100, 100, ['mode' => 'crop']) ?>" />
update
If you are using media finder then you can not use getThumb on the file as it will be just path for that file so its not possible to resize that image using getThumb [ Its only possible with relational attachments (attachMany, attachone etc...) ]
Although you can use this to show small image
<img height="64" width="64" src="<?= 'https://october-plaza.com/storage/app/media/'
. $model->photo ?>"` />
you can add this height="64" width="64" to show image as thumbnail (but it will be full image just scale down using attributes).
if any doubts please comment
You can do this with OCTOBER IMAGE RESIZER plugin in your columns.yaml file
Usage in Backend List
The image resizer can also be used on backend lists with the type of thumb, e.g.
image:
label: Image
type: thumb
sortable: false
This works with:
AttachMany (uses first image) Docs
AttachOne Docs
Mediafinder Docs
You can also optionally pass width (default 50), height (default 50) and options as follows:
image:
label: Image
type: thumb
sortable: false
width: 75
height: 100
options:
mode: crop
i want to make qrcode, in there i can make it but i have something trouble when i want to change the format of qrcode to png file. but its only show symbol
here my view :
<?php echo QrCode::size(265)->generate($row->id) ?>
this qrcode i use :
"simplesoftwareio/simple-qrcode": "~1"
here my referance : https://www.simplesoftware.io/docs/simple-qrcode
can anyone help me ? or can someone give me solution ?
before i change format to png :
and this after i change it :
There are more simple example available as well.
<img src="data:image/png;base64, {!! base64_encode(QrCode::format('png')->size(100)->generate('QrCode as PNG image!')) !!} ">
If you are formatting it as png file format, you need to include it with a <img> tag.
Taken from the documentation
//Inside of a blade template.
<img src="{!!$message->embedData(QrCode::format('png')->generate('Embed me into an e-mail!'), 'QrCode.png', 'image/png')!!}">
You can also do this:
$png = QrCode::format('png')->size(512)->generate(1);
$png = base64_encode($png);
echo "<img src='data:image/png;base64," . $png . "'>";
In controller
$path = getenv('IMAGE_URL')."/img/logo.png";
$png = QrCode::format('png')->merge($path, .17, true)->size(300)->errorCorrection('H')->generate($data);
$png = base64_encode($png);
In blade file
<img src='data:image/png;base64,{{$png}}'>
I came to this page because I needed to create a PNG file to send inline in an email in laravel8.
I used the examples above in order to create the QR code as a png which worked brilliantly. I used the following code:
<img src="data:image/png;base64, {!! base64_encode(QrCode::format('png')->size(100)->generate('QrCode as PNG image!')) !!}" />
However a number of email services (including Gmail) do not display images that use inlined base64 as above. Instead, they require you to add the base64 image as an attachment to the email and then reference that attachment in the img src.
Thankfully laravel (I'm using laravel8) has a really cool function that does this for you, so my code ended up looking like this (which worked):
<?php
$qrCodeAsPng = QrCode::format('png')->size(500)->generate("my text for the QR code");
?>
<img src="{{ $message->embedData($qrCodeAsPng, 'nameForAttachment.png') }}" />
The $message variable is one that is in every blade that is being sent as an email in laravel. In my case I did not want to create an actual image on the server, but if you wanted to use an image that you had stored you would use $message->embed().
Is there a way to check if the file exists in Twig for an image uploaded in a newly created post?
The way I have my post setup is if an image is not uploaded the Twig template will show an empty box with the proportions of where the image should be, but it's a blank box that's awkward to look at.
Question, is if there is a specific command to use with an if statement to check if a file exists if so, display the image code if not do not display the image code.
Image code: (this is the code I want to hide if no image exists to get rid of the empty box)
<div class="entry-thumbnail">
<img width="230" height="172" src="{{ asset(['images/', post.image]|join) }}" class="" alt=""/>
</div>
you could write a twig extension and use some code like this:
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Filesystem\Exception\IOException;
use Symfony\Component\Finder\Finder;
$this->fs=new Filesystem();
if (!$this->fs->exists($directory)) {
$this->logger->info("there is no ".$directory." ...");
} else {
$this->logger->info("Directory ".$directory." already exists.");
}
but i would rather use javascripz like
in your img tag :
<img ... onError="this.src='imagefound.gif';" />
update:
The image Tag has an onError-Handler that triggers when the image in the src attribute is not found. So instead of using this simple inline syntax you could do the same like :
pseudo jquery code:
$(document).on('error','img',function(){
$(this).attr("src","../path/to/placeholerImage.png");
});
I have created a custom image attribute and added it to default attribute set in Magento. My new attributes are img_support and img_upgrade. I've displayed both images on product view page using this piece of code:
<?php if ($_product->getimg_upgrade()):
$_img = '<img src="'.$this->helper('catalog/image')->init($_product, 'img_upgrade')->resize(85).'" alt="'.$this->htmlEscape($this->getImageLabel()).'" title="'.$this->htmlEscape($this->getImageLabel()).'" "/>';
echo $_helper->productAttribute($_product, $_img, 'img_upgrade');
endif;
?>
Same code with the second custom image attribute name will display img_support image. When I set images and select them for these two attributes they'll display fine but when there is no image uploaded and selected for these attributes and I try to show it on product view page then it generates an error. Something like this:
a:5:{i:0;s:25:"Image file was not found.";i:1;s:3911:"#0 C:\Program Files\EasyPHP- 5.3.8.0\www\mymagentoroot\app\code\core\Mage\Catalog\Helper\Image.php(163):
Mage_Catalog_Model_Product_Image->setBaseFile('no_selection').....
And a long trace after that. So basically it fetches the image even though there is no image selected. Can anyone tell me how can I display my custom images in product view page of selected products? I have, say 10 products with default attribute set. So all of these 10 products CAN be set with img_support and img_upgrade but I want to show the custom images only on 5 selected products. If the images are set display. Otherwise don't. How can i do this? If there is any other proper or better way to do this then help me out here.
Thanks!
When a product has no image for a given attribute, Magento uses a placeholder image instead.
Basically, each image attribute must have a placeholder image in the skin directory, named with the corresponding attribute code.
In your case, you should create two new placeholder images for your two new attributes img_support and img_upgrade, in this skin directory : images/catalog/product/placeholder/your_attribute_code.jpg (either with a new image, or with a copy of one of the base placeholders)
This problem also happens if you upload image for that attribute then suddenly remove image file via FTP. It is not good to show the site down. To summarize, there are 3 ways to fix this:
1) Answer of #blmage: use place holder
2) Use try catch:
<?php
try {
if ($_product->getimg_upgrade()):
$_img = '<img src="'.$this->helper('catalog/image')->init($_product, 'img_upgrade')->resize(85).'" alt="'.$this->htmlEscape($this->getImageLabel()).'" title="'.$this->htmlEscape($this->getImageLabel()).'" "/>';
echo $_helper->productAttribute($_product, $_img, 'img_upgrade');
endif;
}
catch (Exception $e) {
}
?>
Check if the file is existed
getBaseMediaPath();
$baseFile = $baseDir . $_product->getImgUpgrade();
if (file_exists($baseFile)) {
}
?>
I am trying to replace the default lightbox 'modal' to 'slimbox', because 'modal' doesn't have the navigation arrows.
Demo of slimbox with navigations
Demo of modal without navigations
I am using these paths to modify the calling of slimbox
[templatename]/html/com_virtuemart/productdetails/default.php
components/com_virtuemart/productdetails/default.php
Joomla v2.5
Virtuemart 2.0.6
Slimbox2
The following is my attempt:
//Enable Slimbox2 plugin
$front = JURI::root(true).'/components/com_virtuemart/assets/';
$document = JFactory::getDocument();
$document->addStyleSheet($front.'js/slimbox/slimbox.css');
$document->addScript($front.'js/slimbox/slimbox2.js');
$js = 'jQuery(document).ready(function($) { $("a.lightbox").slimbox(); });';
$document->addScriptDeclaration($js);
//output thumbnail
echo $this->product->images[0]->displayMediaThumb('class="product-image"',true,'class="lightbox" rel="lightbox"'.$this->product->virtuemart_product_id.'"',true,true);
//unset first image not to be show amont additional ones
unset ($this->product->images[0]);
?>
But its still not working I wondered what's wrong?
[Reference][3]
You aren't applying the slimbox class to the image reference, your applying it to the container of the image aren't you? You need to deal with the image file url directly in my opinion.
// get the file_url of the first image
$imgPath = $this->product->images[0]->file_url;
// output the image
<a class="slimbox" href="<?php echo $imgPath; ?>">
<img src="<?php echo $imgPath; ?>" alt="" />
</a>