I need to show an image in frontend.
<div class="col-md-12">
<f:debug>{user.image.0}</f:debug>
<f:if condition="{user.image}">
<f:then>
<f:image image="{user.image.0}" width="100" alt="" />
</f:then>
<f:else>
</f:else>
</f:if>
</div>
Debug of user.image gives this
TYPO3\CMS\Extbase\Domain\Model\FileReferenceprototypepersistent entity (uid=34, pid=8)
uidLocal => protected 16 (integer)
originalResource => protected NULL
uid => protected 34 (integer)
_localizedUid => protected 34 (integer) modified
_languageUid => protected 0 (integer) modified
_versionedUid => protected 34 (integer) modified
pid => protected 8 (integer)
But in frontend I get this error
1476107295: PHP Catchable Fatal Error: Object of class TYPO3\CMS\Extbase\Persistence\ObjectStorage could not be converted to
string in
I have tried to use both image=" and src=" but nothing works.
Does it have anything to do with GraphicsMagick not being installed on the server?
The reason for your problem probably is the usage of {user.image.0}.
While in earlier versions of fluid you could find the first image of an array in this way, in newer versions the array needs another handling:
<f:for each="{user.image}" as="userimage" iteration="iterator">
<f:if condition="{iterator.isFirst}"><f:image image="{userimage}" width="100" alt="" /></f:if>
</f:for>
Related
I'm a on learning stage, and a little bit of a noob, sorry if this is a stupid question. I'm working on a Movie DB project, with movies from live API, Favorite list, JWT auth, etc. I'm now on the end part, have everything done so far, and have one problem. Every person who click's on see details about movie, the movie will be sent on my DB. And with this user can save movie to his favorite table (.net Crud operations). Everything work but when I want to get movies from a table that's between movies table and users table (favorite table many to many relation) I get a error in my swagger everything is working, and I can get every movie that's in favorite, but in angular I user *ngFor, and the error say that it must return a array, but I'm getting a Object, every other get request works only this one doesn't. Here is my code and error:
You can see I get everything I want in console, but UI is Error
Component .ts and HTML:
//HTML
<div *ngFor="let fav of requests" class="col-xl-3 col-lg-4 col-md-6 col-sm-6 col-xs-12">
<div class="card">
<img src="{{fav.Poster}}" class="card-img-top">
<div class="card-body">
<p class="card-text"> {{fav.Title}}</p>
</div>
</div>
</div>
.Ts
export class FavoriteListComponent implements OnInit {
constructor(public service: MovieService) { }
requests: any = [];
ngOnInit(): void {
this.getFav();
}
getFav(){
this.service.getFavorite1().subscribe(
res => {
this.requests = res;
console.log(res)
});
}
}
MovieService
getFavorite1(){
return this.http.get('http://localhost:5002/api/Favorite/getUsersFavorite').pipe(map(res => res));
}
And this is my get request in .Net 5
[Authorize]
[HttpGet("getUsersFavorite")]
public async Task<IActionResult> GetUsersFavoriteMovies()
{
string userId = User.Claims.First(a => a.Type == "UserID").Value;
var user = await _context.DbUsers.Where(n => n.Id == Int32.Parse(userId)).Select(movies => new FavoriteView()
{
ImdbId = movies.Favorites.Select(n => n.ImdbId).ToList(),
Title = movies.Favorites.Select(n => n.Movies.Title).ToList(),
Poster = movies.Favorites.Select(n => n.Movies.Poster).ToList()
}).FirstOrDefaultAsync();
return Ok(user);
}
I tried a lot of thing, the closest I get is this, and when I change in .net request the .FirstOrDefaultAsync() to .ToListAsync(). When I it to ToListAsync I get this:
In this case I don't get any error but nothing is showing in UI
I know the question is big, but I'm desperate, I'm stuck on this a few day's, and every help is great. Thank you!!!
Use this way, it will work.
<ng-container *ngIf="requests">
<div
*ngFor="let fav of requests.imdbId; index as i"
class="col-xl-3 col-lg-4 col-md-6 col-sm-6 col-xs-12"
>
<div class="card">
<img [src]="requests.poster[i]" class="card-img-top" />
<div class="card-body">
<p class="card-text">{{ requests.title[i] }}</p>
</div>
</div>
</div>
</ng-container>
Example:
https://stackblitz.com/edit/angular-ivy-f251ko?file=src%2Fapp%2Fapp.component.html
I started to prepare localization strings for my application based on Laravel 8.19, and I found that nested arrays are not working.
I copied auth.php from \resources\lang\en to \resources\lang\ru and added few strings in nested array
'login' => 'Войти',
'logout' => 'Выйти',
'password' => [
'definition' => 'пароль',
'forgot' => 'Забыли пароль?',
],
'remember' => 'Запомнить меня',
'failed' => 'Учетные данные не совпадают с нашими записями.',
'password' => 'Пароль неверный.',
'throttle' => 'Слишком много попыток входа. Пожалуйста попробуйте снова через :seconds секунд.',
Then in login page \resources\views\auth\login.blade.php I try to echo lang strings.
<div class="flex items-center justify-end mt-4">
#if (Route::has('password.request'))
<a class="underline text-sm text-gray-600 hover:text-gray-900"
href="{{ route('password.request') }}">
{{ __('auth.password.forgot') }}
</a>
#endif
<x-button class="ml-3">
{{ __('auth.login') }}
</x-button>
</div>
But auth.password.definition and auth.password.forgot are not working. I see "auth.password.definition" on the page like I don't have this string defined in the auth.php file. What can be wrong?
I found in my old project on Laravel 5 that I used the trans() function to retrieve localization strings, and it also worked with nested arrays like above. Now trans() cannot help with that.
It seems that nested arrays notation for localization strings replaced with simple DOT delimiter in KEY name, because I tried like that and it works.
'password.forgot' => 'Забыли пароль?',
Error
The CSRF token is invalid. Please try to resubmit the form.
This error appearing sometimes in symfony2 forms , but after refreshing form saved succesfully.
This error is not frequrent it happening sometimes while saving form.
I have tried in every browser issue is same.
On Refresh of Page Token get refresh in hidden input fields But error remains the same.
i have googled and found some helpfull article which suggest
{{form_rest(form)}}
to use before closing of form tag.
Here is my code
Twig code
<div id="{{ formID }}_container" class="main">
<div class="page">
<div id="{{ formID }}_output"></div>
{% include 'Bundle:Form:required_msg.html.twig' %}
{{form_start(form, { 'attr' : { 'id': formID } })}}
<div style="display: none">
{{form_rest(form)}}
</div>
{{form_end(form)}}
</div>
</div>
I have this hidden field:
<input id="form_id" name="details_form[_token]" value="somevalue" type="hidden">
This is my form data:
details_form[_token] value
details_form[age]
details_form[gender] F
This is the request response:
{"success":false,"msg":"Form is invalid.","errors":[{"name":"[0]","message":"The CSRF token is invalid. Please try to resubmit the form."}]
Some other answer I've seen on Stack Overflow (The CSRF token is invalid. Please try to resubmit the form) says to do this:
public function setDefaultOptions(OptionsResolverInterface $resolver) {
$resolver->setDefaults(array(
'options' => array(),
csrf_protection' => false
));
}
But, my mequirement is not to set the csrf_protection flag to false. Can anyone suggest the best to way to handle this issue?
I want to display multiple ads on Facebook instant articles. I found this code, which I tried manually and its working.
<section class="op-ad-template">
<!-- Ads to be automatically placed throughout the article -->
<figure class="op-ad">
<iframe src="https://www.mywebsite.com/ss;adtype=banner300x250&adslot=1" height="300" width="250"></iframe>
</figure>
<figure class="op-ad op-ad-default">
<iframe src="https://www.mywebsite.com/ss;adtype=banner300x250&adslot=2" height="300" width="250"></iframe>
</figure>
<figure class="op-ad">
<iframe src="https://www.mywebsite.com/ss;adtype=banner300x250&adslot=3" height="300" width="250"></iframe>
</figure>
</section>
Now I am trying to make it possible via Facebook Instant Article Plugin. I didn't find any setting option for these type ads.
I tried to search on google and can't find anything except this:
https://developers.facebook.com/docs/instant-articles/sdk/transformer-rules
Please help me!
A. How to add multiple ads using FB INSTANT ARTICLE PLUGIN in wordpress?
B. How to add different codes using FB INSTANT ARTICLE PLUGIN in wordpress?
You can do this by adding the instant_articles_transformed_element filter, in order to modify the header accordingly.
This is generally used when placing Facebook Audience Network units, but if your manual code worked, the following code should work, although you might need to play around with the query vars. Add to functions.php the following:
At the top of functions.php, add this:
use Facebook\InstantArticles\Elements\Ad;
And then:
/**
* Adds multiple units to the Instant Article
*
* #param Instant_Articles_Post $article
*
* #return Instant_Articles_Post
*/
add_filter('instant_articles_transformed_element', function ($article) {
// Create the base ad
$ad = Ad::create()
->withWidth(300)
->withHeight(250)
->enableDefaultForReuse();
// Retrieve the header
$article->getHeader()
// Add the first ad
->addAd(
$ad->withSource(
// This creates the URL https://www.mywebsite.com/ss;adtype=banner300x250;adslot=1
add_query_arg(
array(
'adtype' => 'banner300x250',
'adSlot' => '1',
),
'https://www.mywebsite.com/ss'
)
)
)
// Add the second ad
->addAd(
$ad->withSource(
// This creates the URL https://www.mywebsite.com/ss;adtype=banner300x250;adslot=2
add_query_arg(
array(
'adtype' => 'banner300x250',
'adSlot' => '2',
),
'https://www.mywebsite.com/ss'
)
)
)
// Add the third ad
->addAd(
$ad->withSource(
// This creates the URL https://www.mywebsite.com/ss;adtype=banner300x250;adslot=3
add_query_arg(
array(
'adtype' => 'banner300x250',
'adSlot' => '3',
),
'https://www.mywebsite.com/ss'
)
)
);
return $article;
});
With that code, the plugin will take care of the rest, and it will automatically add the following code to the head section:
<meta property="fb:use_automatic_ad_placement" content="enable=true ad_density=default"/>
It will also add the following right before closing the header:
<section class="op-ad-template">
<figure class="op-ad op-ad-default">
<iframe src="https://www.mywebsite.com/ss?adtype=banner300x250&adSlot=1" width="300" height="250"></iframe>
</figure>
<figure class="op-ad">
<iframe src="https://www.mywebsite.com/ss?adtype=banner300x250&adSlot=2" width="300" height="250"></iframe>
</figure>
<figure class="op-ad">
<iframe src="https://www.mywebsite.com/ss?adtype=banner300x250&adSlot=3" width="300" height="250"></iframe>
</figure>
</section>
So, my next problem on a rails project is the following: I am using the asset pipeline to serve my assets. Now I want to include inline css into a view with a background image. because of the asset pipeline I am just able to use the helpers that rails offers from ground. But the problem is, that every helper (except image_tag is delivering the wrong output).
image_url('work-1.png') # => /images/work-1.png
image_path('work-1.png') # => /images/work-1.png
asset_url('work-1.png') # => /work-1.png
asset_path('work-1.png') # => /work-1.png
image_tag('work-1.png') # => <img ..........> # Only right tag!
Yeah, that didn't help me. And also all other questions I found about this topic.
Would be nice to know what the issue is with this. Thanks!
The image_tag helper is the only method out of your list that will actually produce an html tag.
The image_url helper actually use the image_path helper to compute the full path to an image (eg. http://www.example.com/image/image.png)
The image_path helper produces the relative path to an image (eg. /images/foo.png)
image_tag output
image_tag("icon") # => <img alt="Icon" src="/assets/icon" />
image_tag("icon.png") # => <img alt="Icon" src="/assets/icon.png" />
image_tag("icon.png", size: "16x10", alt: "Edit Entry") # => <img src="/assets/icon.png" width="16" height="10" alt="Edit Entry" />
image_tag("/icons/icon.gif", size: "16") # => <img src="/icons/icon.gif" width="16" height="16" alt="Icon" />
image_tag("/icons/icon.gif", height: '32', width: '32') # => <img alt="Icon" height="32" src="/icons/icon.gif" width="32" />
image_tag("/icons/icon.gif", class: "menu_icon") # => <img alt="Icon" class="menu_icon" src="/icons/icon.gif" />
image_path output
image_path("edit") # => "/images/edit"
image_path("edit.png") # => "/images/edit.png"
image_path("icons/edit.png") # => "/images/icons/edit.png"
image_path("/icons/edit.png") # => "/icons/edit.png"
image_path("http://www.example.com/img/edit.png") # => "http://www.example.com/img/edit.png"
Another question answered myself.
I had the wrong path in the image_path helper. So, if you have a missing image (that cannot be found by the asset pipeline, the helper is falling back to the /images path.
Let's imaging I want to include a path of ph/image-1.png into my document. image_path('ph/image-1.png') will put the right directory with the path. Otherwise, if you are going to use image_path('image-1.png') it will use the /images directory in front of the image you are going to use. But this cannot be found. This was my fault.
To wrap it up, here is the summary:
image_path('ph/image-1.png') # => /assets/ph/image-1.png
image_path('image-1.png') # => /images/image-1.png