i have different type of users in my application and each user have differerent type of background image for their wall like facebook but here i am confused ho to chang each user background image dynamically as their images name are coming from database and background image class is defined in css file . any solution will be highly appreciated as i am new to laravel and php . thnks
as for laravel blade template engine the code will be like this
#if(isset($data->coverphoto))
<img src="{{asset('$data->coverphoto')}}" title="" />
#elseif(empty($data->coverphoto) || $data->coverphoto == null)
<img src="asset('placeholder.jpg')" title="" />
#endif
first we will check if the data is existing or not then we will place image as a img tag another option is that we will use class like
.coverphoto{
background-image: url('<?= (isset($data->coverphoto))?asset('images/') . $data->coverphoto: asset('images/placeholder.jpg') ?>');
}
<div class="coverphoto"> </div>
Related
I'm working with Laravel 5.8 and in this project I want to show some images that I had uploaded through database like this:
And at the view, I tried this:
<div class="text-center" style="background-image: url('public\images\tavana\{{ $images[0]->path }}');height: 220px;">
But the problem is the image does not load!
However the image already exists at the this directory:
public\images\tavana\imagename.jpg
And other data such as title, subtitle properly shows up.
So how to properly show the image?
use asset to generate url
<div class="text-center" style="background-image: url('{{asset('images/tavana/'.$images[0]->path)}}');height: 220px;background-repeat: no-repeat">
also not sure why you are accessing 0th index $images[0]->path instead you can return first() so it will be $images->path
If you have multiple then use loop
You can't try:
<div class="text-center" style="background-image: url({{url('/')}}.'public/images/tavana/{{ $images[0]->path }}');height: 220px;background-repeat: no-repeat">
I am using Drupal 8 and i created a page where i display an image and a form inside a block as an inline template.
This looks like this :
<div class="col-md-6" style="padding-right:0px; padding-left:0px;">
<img src="{{ base_path ~ directory }}/sites/default/files/Dinard_S.jpg" id="b-frm-img" style="width: 400px; height:300px;"></div>
Then another div contains my form. What i'm trying to do is to make user with no code knowledge able to change this specific image from the drupal admin.
Is there any way to do this?
I created an admin page to upload an image in a dedicated folder using managed_file type in the form. Seems there is no better ways.
I am using Laravel, and I want to display an image. I have the public/img folder, and this is the code
<img src="{{ URL::asset("img/background1.jpg") }}" alt="Unsplashed background img 1">
The image does not appear. When I inspect the page however, it returns the correct link, http://localhost:8000/img/background1.jpg but it says 0x0 px.
Add a / in front as the public folder is the root...
<img src="{{ URL::asset("/img/background1.jpg") }}" alt="Unsplashed background img 1">
Are you getting correct image when you open this link in browser? If so, then it would be issue with img height-width. Try setting static height-width for img and check.
Hope this helps..
Hi i am trying to get an image to display when a result is picked from a data base this is my code below:
$box .= '<div style="margin-top:10px;height:120px;"id=\"Video\">
<br/>
<div style="border-style:solid;border-width:1px;border-color:#00000;width:400px;float:right;"id=\"Title\">'.$row['title'].'</div>
<div style="width:220px;height:150px;float:left;border-style:solid;border-width:1px;border-color:#000000;" id=\"VideoImage\">"
<img class="partimg1" src="classroom/images/'.$row['media_id'].'.jpg" /></div>
<div style="height:50px;width:400px;float:right;padding:2px;margin-bottom:5px;" id=\"Blurb\">'.$row['blurb'].'</div>
<div style="height:21px;width:152px;margin-top:45px;margin-left:7px;background:url(images/bg_top_img2-09.jpg) repeat-x;color:#ffffff;padding-left:2px;float:left;border:1px solid #000000;position:relative;border-radius:15px;text-align:center;" id=\"Downloads\"> Download </div>
</div>';
the line with in the middle is where the image should be the .$row['media_id']. this will be a value from the database it will only be a number so for example 1 up to 50 and in the images folder the images are named 1 to 50 and they are all JPG is there something that i have missed because i have used this before and it worked.
all that displays on the screen is a broken image link like when the web page cannot find the image in the folder.
any help would be much appreciated.
You break the src link.
src=\"classroom/images/'.$row['media_id'].'.jpg\"/>
As you use simple quote ' for string delimiter, you don't need to escape double ones "
<img class=\"partimg1\" src=\"classroom/images/"'.$row['media_id'].'".jpg\"/>
Should be
<img class="partimg1" src="classroom/images/'.$row['media_id'].'.jpg" />
You also need to fix all your id attributes
i am trying to have different header background images depending on which inner page is accessed. Right now i have the same picture for all inner pages and need the php code changed so its conditional. Like if im on contact page, 1.jpg to be set as header img. If on services page, 2.jpg to be set as header img etc, you get the idea.
Here is the php code ive found in this wp theme im trying to improve for a friend:
<div class="bgtop">
<?php
//display featured image if one exists
$featimage = get_bloginfo('stylesheet_directory') . "/images/pageheader.png";
if ((has_post_thumbnail( $post->ID ))&&(!is_single()&&(!is_category())) ){
$image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' );
$featimage = $image[0];
}
?>
<div class="pageheader" style="background: url(<?php echo $featimage; ?> ); background-position: center top;">
<div class="centermenu">
<div class="pagelogo">
<!--<a href="<?php bloginfo('home'); ?>">
<img src="<?php bloginfo('stylesheet_directory'); ?>/images/indexlogo.png" alt="logo" />
</a>-->
</div>
Well.. It's more of a structure thing. How are you determining which page they are on? Does the user click a link? Use the information available to the server to decide what content to serve. If you're using one script to serve all your pages, then you'll need to pass it a parameter when the user clicks a link. You can do this by making your links take parameters.
Markup like so:
<a href='default.php?page=home'> Navigate To Home </a>
<a href='default.php?page=blog'> Navigate To Blog </a>
php like so:
if($_POST['page'] == "home")
echo $homeheader;
elseif($_POST['page'] == "blog")
echo $blogheader;
But, usually you just make multiple php pages that include some common elements (called templating). That helps keep things cleaner than making one php script that serves up your whole site.
If you're wanting the manage this in the back-end of WordPress: You can use the Advanced Custom Fields Plugin for WordPress (http://wordpress.org/plugins/advanced-custom-fields/). Through it, you can add a field on every page an even every post that allows you to enter in a background image.
Then, in your header.php template file, add the shortcode somewhere in your body tag:
<body background="(<?php the_field('background_image')" ?>)">
Depending on what page you're on, it will show that background image.
If You'd like the process automated: You can create a folder called "bg" and have an image with the same name as your page. For example, for about.php you can have about.jpg.
Then write a script that takes the page name, and then sets the background image to that name. You would place this in the header.php file in your template Something like:
$page = end(explode("/",$_SERVER['REQUEST_URI']));
$image = str_replace("php","jpg",$page);
Then use:
<body background="bg/<?php print $image ?>">
This is assuming that you are keeping your image files in http://www.yoursite.com/bg/ But you can also use shortcodes to keep these images within your theme with <?php echo get_template_directory_uri(); ?>