Hi,
In
@model HomeVM
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>@Model.Basics.FirstName @Model.Basics.LastName</title>
<link href="assets/css/styles.css" rel="stylesheet">
<link href="assets/css/animation.css" rel="stylesheet">
<link href="assets/css/slick.css" rel="stylesheet">
<!--[if lt IE 9]>
<script src="assets/js/html5shiv.js"></script>
<script src="assets/js/respond.min.js"></script>
<script src="assets/js/placeholder.js"></script>
<![endif]-->
This file has been truncated. show original
image URL:s are generated by doing the following:
@if (Model.Basics.Image?.Length > 0)
{
<img src="@Model.BuildImageUrl(Model.Basics.Image[0])?width=512&height=516&mode=Crop" alt="@Model.Basics.FirstName @Model.Basics.LastName" class="pull-left" />
}
else
{
<img src="assets/images/placeholder.jpg" alt="@Model.Basics.FirstName @Model.Basics.LastName" class="pull-left" />
}
The BuildImageUrl Func is used. I managed to declare and initialize it in my Razor Pages Page Model by creating a constructor and passing in SquidexOptions
.
Now when I take a look at the generated URL it looks like this:
<img src="/api/assets/813d1a8a-604b-43f9-84ad-2f4152af76fa?width=50&height=50&mode=Crop" />
Looks OK except that it is relative to the client application and not the CMS. If I put the protocol and domain name of my CMS it is obviously going to work. But how can I achieve this in a nice clean way?
The sample is outdated, I would use the following method:
{
Guard.NotNull(serviceUrl, nameof(serviceUrl));
Guard.NotNull(authenticator, nameof(authenticator));
Guard.NotNullOrEmpty(applicationName, nameof(applicationName));
this.authenticator = authenticator;
this.applicationName = applicationName;
this.serviceUrl = serviceUrl;
}
public string GenerateImageUrl(string id)
{
return id != null ? $"{serviceUrl}api/assets/{id}" : id;
}
public string GenerateImageUrl(IEnumerable<string> id)
{
return GenerateImageUrl(id?.FirstOrDefault());
}
public static SquidexClientManager FromOption(SquidexOptions options)
I will update the sample.
I have updated the sample
Thanks for the quick reply Sebastian.
I got it working - I had missed to configure the Squidex middleware in Startup.cs ;s