I have a problem with smarty framework, so I need to verify if an image name starts with 'http':
I try this code:
{foreach from=$video->result() item=v}
{if substr($v->image,0,4) eq 'http'}
<img src="{$v->image}" alt="">
{else}
<img src="{$IMG_URL}videos/images/{$v->date|date_format:'%Y'}/{$v->date|date_format:'%m'}/{$v->image}" alt="">
{/if}
{/foreach}
Help me please..Exists another way?
This code should work fine. Probably your data is not set properly.
Consider the following testing code:
PHP file:
class V {
public $image = 'http://rwewreuiuiwre';
}
$smarty->assign('v', new V());
Template file:
{if substr($v->image,0,4) eq 'http'}
http
{else}
non http
{/if}
It works fine. If you change $image to hxttp you get non http message
Related
I would like to check whether an asset {{ asset }} exists before trying to output the file.
I have tried a few things after some google-ing, but none seem to work on Laravel 5.0.
An example of what i would imagine the request (in a frontend blade view) to look like;
#if(asset(path-to-asset))
<img src="image-path"/>
#else
<img src="no-image-path"/>
#endif
Thanks
It would be better to handle this from the webserver, as just because the file exists, doesn't mean it'll be accessible to the public web. Also means you're not repeating code all over the place to check if the file exists see: Replace invalid image url with 404 image
However this can be done PHP wise
#if (file_exists(public_path('path/to/asset.png')))
<img src="{{ asset('path/to/asset.png') }}">
#else
<img src="{{ asset('path/to/missing.png') }}">
#endif
Well aside from using native php methods here
You could use:
if (File::exists($myfile)){ ... }
However, you should note that asset(...) will return an absolute URL to the asset, but you need to check its existence on the file system, so you'll need a path like:
$img = path('public').'/path/to/image.png';
Try this way:
For Laravel:
<?php
$image = parse_url($user->image);
if(isset($image['host'])){
$image= $user->image;
}
else if($image==null){
$image= Request::root().'/uploads'.'/subsystems_icons/'.'democp.jpg';
}
else {
$image= Request::root().'/uploads/'.$user->image;
}
?>
<div class="">
<img class="image" style="width: 100%; height: 300px; object-fit: contain ;"
src="{{$image}}">
</div>
My image file path is public/img/stuvi-logo.png and
my app.blade.php file path is resources/views/app.blade.php
Inside of my app.blade.php file I use {{HTML::image('/img/stuvi-logo.png')}}
to display an image.
I don't understand why this won't find the image.
What is the root folder of the image() method?
If you use bootstrap, you might use this -
<img src="{{URL::asset('/image/propic.png')}}" alt="profile Pic" height="200" width="200">
note: inside public folder create a new folder named image then put your images there. Using URL::asset() you can directly access to the public folder.
Change /img/stuvi-logo.png to img/stuvi-logo.png
{{ HTML::image('img/stuvi-logo.png', 'alt text', array('class' => 'css-class')) }}
Which produces the following HTML.
<img src="http://your.url/img/stuvi-logo.png" class="css-class" alt="alt text">
Update After Laravel 5 this package has been deprecated and maintained as a separate external package. in order to work need to add this composer require laravelcollective/html. more details https://laravelcollective.com/
as of now, you can use
<img src="{{ asset('images/foo.png') }}" alt="tag">
In Laravel 5.x you can use laravelcollective/html and the syntax:
{!! Html::image('img/logo.png') !!}
It will look for an image inside of a public/storage folder where you can define your own image folder
<img src="{{ Storage::url($post->image->path) }}" alt="">
Always try to dump what you are looking for first and than pass it to a url method.
Also, you can create your own url() method inside your Image model if you have some
public function url()
{
return Storage::url($this->path);
}
Then in your blade template you can use this method as follows:
<img src="{{ $post->image->url() }}" alt="">
Had the same problem with laravel 5.3...
This is how I did it and very easy.
for example logo in the blade page view
****<image img src="/img/logo.png" alt="Logo"></image>****
In Laravel 5.x, you can also do like this .
<img class="img-responsive" src="{{URL::to('/')}}/img/stuvi-logo.png" alt=""/>
you can Using asset() you can directly access to the image folder.
<img src="{{asset('img/stuvi-logo.png')}}" alt="logo" class="img-size-50 mr-3 img-circle">
in my case this worked perfectly
<img style="border-radius: 50%;height: 50px;width: 80px;" src="<?php echo asset("storage/TeacherImages/{$studydata->teacher->profilePic}")?>">
this code is used to display image from folder
Assuming the file you want to display is public try adding the variable in your Mail builder function.
public function toMail($notifiable)
{
$img_url = env('APP_URL')."/img/stuvi-logo.png";
return (new MailMessage)
->subject('Test')
->markdown('vendor.mail.markdown.message', [
'data' => $this->data,
'img_url'=>$img_url
]);
}
And then use your 'img_url' variable set in the array in your email blade file.
< img src={{img_url}} alt="Logo" height="50"/>
This worked for me on Laravel 8.xx.
I am using the codeigniter framework with the summernote editor.
If I use a single page in php post without the framework, the result is just like this:
<span style="font-weight: bold;">asdasdasd</span>
But if I use post in codeigniter the result is different, like this:
<span bold;">asdasdasd</span>
style='font-weight: ' is missing..
Why did it happen, and what is the solution?
Thank you for helping.
I got the answer...
in codeigniter don't use :
$_POST['content'] OR $_GET['content']
but use :
$_REQUEST['content']
PROBLEM SOLVED!
I think that is a xss filter problem, try to disable or get the value to false.
$content = $this->input->post('content', FALSE);
I've edited with original summernote example:
<div class="span12">
<h2>POST DATA</h2>
<pre>
<?php print_r($this->input->post(NULL, FALSE)); ?>
</pre>
<pre>
<?php echo htmlspecialchars($this->input->post('content', FALSE)); ?>
</pre>
</div>
Following is my code snippet from smarty template :
<div id="entrancelist">
<h2 class="heading">My Packages</h2>
{if $user_study_test_packages.test}
<ul class="entrancelist">
{foreach from=$user_study_test_packages.test item="user_test_packages" key=key}
<li>
<h4>{$user_test_packages.pack_name|capitalize:true}</h4>
{if $user_test_packages.pack_expiry_date1 >= $current_date }
<div class="fr"><span class="expiry">Expiry : {$user_test_packages.pack_expiry_date}</span></div>
{else}
<div class="fr"><span class="expiry_dt">This package is expired on {$user_test_packages.pack_expiry_date}.</span></div>
{/if}
<p class="descp">{$user_test_packages.test_pack_desc}</p>
<div class="srtest"> </div>
</li>
{/foreach}
</ol>
{else}
You haven't bought any online test packages
{/if}
</div>
Now what I want to do is reaplace the text "You haven't bought any online test packages" with the content of different URL say www.google.com But I'm not understanding how should I achieve this. Can anyone help me out in this issue? Thanks in advance.
Why not keep PHP separate from the template?
Maybe do this in your php code,
<?php
$gcontent = file_get_contents('http://www.google.com');
$smarty->assign('gcontent',$gcontent);
?>
Then you can use {$gcontent} in your template.
You can even use query string parameters with the URL if you wanted to. More info on the php function.
http://www.w3schools.com/php/func_filesystem_file_get_contents.asp
Something like this works for me in Smarty 3, but some might not consider it very elegant:
...
{else}
{file_get_contents('http://www.google.com/')}
{/if}
I use codeigniter pagination class in my project it's works fine for me . But there is no option to tell class just show next and previous link ,
please see this image I want to show result paged plus I'd like to use to link for next and previous instead of numeric links and when the user click on the next button I'll use Ajax to retrieve request I don't have problem with Ajax calls in pagination in numeric links but I want to just show this to link :)
I don't think I can explain what I need very good so please see the image .
link text
Here is my view file :
<div style="height:200px; position:relative">
<div id="left_nav"></div>
<div id="right_nav"></div>
<div style="width:622px;margin:0 auto;">
<!-- Gallery Box1 -->
<?php foreach($last_profile as $l) : ?>
<div id="galleryBoxHolder">
<div id="galleryBoxContent">
<div id="ImageHolder">
<img src="dummy_data/1.gif" /> </div>
<br />
<p><?=$l->artname?> </p>
<br />
<p style="color:#1a4688">asdasd</p>
<p style="color:#1a4688 ; direction:ltr"><?=$l->length?> cm x <?=$l->width?> cm</p>
</div>
</div>
<?php endforeach ;?>
<div>
<?=$links?>
</div>
<!-- Gallery box1 :off -->
</div>
</div>
Please Check This url which is exactly what I need (#:title Customers Who Bought This Item Also Bought)
In version 2.0.3 Codeigniter - To show Next / Previous only you can add the following config settings:
$config['display_pages'] = FALSE;
$config['first_link'] = FALSE;
$config['last_link'] = FALSE;
You have a couple of options. The first is really simple, hide the thumbnails portion of the pagination module with CSS. The second options isn't too complex either: modify the pagination class to not include the thumbnails, and instead limit its output to the next/prev buttons. This should be somewhat trivial as well.
Line 199 of the System/Libraries/Pagination Library is where the "digits" are handled. This is where you will remove any appending to the $output variable:
if ($this->cur_page == $loop)
{
$output .= $this->cur_tag_open.$loop.$this->cur_tag_close; // Current page
}
else
{
$n = ($i == 0) ? '' : $i;
$output .= $this->num_tag_open.''.$loop.''.$this->num_tag_close;
}