Orchard CMS render media public URL for path in theme razor template - orchardcms

Looking to add a theme setting for a site logo URL to render in the header. However, when using Azure blob storage for images, the URL is not relative and will need to ask the media library for the public URL.
Just wondering what the best way to do this is from the shape template for my header / branding?
Currently is only working with file system media storage:
<a class="logo" href="#Href("~/")">
<img width="103" height="39" alt="" src="#Href(settings.SiteLogoUrl)" >
</a>
Prefer to sore only a relative path in the setting so that any changes to public URL of the Auzre blob storage wont break the site.

Found a solution that works. In the view you can resolve the storage provider, and then use that to get the public URL
#{
var storageProvider = WorkContext.Resolve<IStorageProvider>();
}
<a class="logo" href="#Href("~/")">
<img width="103" height="39" alt="" src="#Href(storageProvider.GetPublicUrl(settings.SiteLogoUrl))" >
</a>

Related

Why are my Razor pages nav links not working using the default pipeline and configuration

I have several links in this base razor project. For some reason my links stopped working. Here is an example:
<a class="nav-link text-dark" asp-controller="Contato" asp-action="Contato">Contato</a>
My project layout is pretty simple:
When I run the project and click on the non working link it goes to this url:
https://localhost:44372/?action=Contato&controller=Contato
However, when I navigate to the correct URL it works fine:
https://localhost:44372/Contato
I did not change any routing in the program.cs and use the default pipeline stuff:
builder.Services.AddRazorPages();
app.UseRouting();
app.MapRazorPages();
Any help in this routing issue?
There are no controllers or actions in a Razor Pages app - only pages. Therefore your anchor tag helpers should use the asp-page attribute:
<a class="nav-link text-dark" asp-page="/Contato">Contato</a>
https://www.learnrazorpages.com/razor-pages/tag-helpers/anchor-tag-helper

Azure AD B2C strips html tags from Custom UI template

While trying to customise the unified (Sign In & Sign Up page), I have this simple HTML in my unified.html template (fragment):
<div class="col-4 login-box gradient-background">
<div>
<h1>WELCOME TO<br/>SuperFancyProductName<sup>®</sup></h1>
</div>
<div id="api" data-name="Unified"></div>
</div>
However, when Azure AD B2C renders the Sign In page, the element is stripped of from inside the h1 element, with this result (fragment):
<div>
<h1>WELCOME TO<br>SuperFancyProductName®</h1>
</div>
In our case, this does not allow us to properly align the ® symbol.
Is there any documentation on what tags are allowed in the template html and how this template transformation actually works?
There is a subset of HTML that is allowed but is not documented.
It looks like the superscript tag is not allowed here. For reference, see this Github issue.
The docs team is still working on an update to show what's allowed.
You can upvote some of the requests in User Voice or create your own request: https://feedback.azure.com/forums/169401-azure-active-directory/suggestions/31173091-improve-the-tag-filtering-on-the-b2c-custom-ui-tem

Doesn't Azure AD B2C Page UI Customization Support Bootstrap?

I'm trying to customize the page UI on Azure AD B2C unified sign in/sign up page.
I was able to create my template and upload all the assets i.e. html page, images and css to my Azure Blob Storage container with the right CORS settings.
When I pull up the page, however, it looks absolutely HORRIBLE! It doesn't seem to support Bootstrap. I read somewhere that no JavaScript is allowed. Is that the reason for this?
Once I upload my custom HTML page, Azure AD B2C seems to be stripping off a lot of the design elements necessary for my customization such as id and style in my body tag -- see below:
<!-- Omitted for brevity -->
<body id="my-login-class" style="url: ('https://myazurestorage.blob.core.windows.net/my-container/my-bg-image.jpg')">
<div id="some-important-id" class="my-important-class">
<div class="col-xs-8">
<div>Some important message</div>
<div>
<div class="col-xs-4">
<div id="api">
</div>
</div>
</div>
</body>
When I inspect the page source once my custom page is rendered, I see that all my classes and Id's are removed along with Bootstrap references e.g. css and js.
Am I getting this right? No Bootstrap which means Azure AD B2C only supports customization of the most basic kind?
Your HTML template can include any external, head, or inline styles but it can't include scripts.
An example of a customized page can be found at the WoodGrove sign-up or sign-in page.
The HTML template for this customized page can be found in the WoodGrove GitHub repository.
This HTML template includes Bootstrap's Reboot styles as well as the WoodGrove's specific styles.
Azure AD B2C creates the head and body elements and then copies the child elements for each of these head and body elements from your HTML template to its HTML document.
Therefore, you shouldn't add attributes to the body element in your HTML template, because they aren't copied.
You can import the bootstrap references. Please see this document: https://learn.microsoft.com/en-us/dynamics365/customer-engagement/portals/azure-ad-b2c
See also: https://github.com/Azure-Samples/active-directory-b2c-php-webapp-openidconnect
It looks horrible for a reason. No styling is applied to the page so that it can be fully customizable. You can reference Bootstrap for CSS; however, I have run in to issues when using bootstrap.js for modals since it appears the Azure B2C API uses bootstrap for modals...In my experience, it is best to rely on Vanilla JS and to leave off any references to third-party JS.
It is possible to use JavaScript if you are using your own custom policies. There are some limitations to JavaScript and the best approach is to try to accomplish anything using the policy first.
To enable JavaScript use the following as guide:
<RelyingParty>
<DefaultUserJourney ReferenceId="SignUpOrSignIn" />
<UserJourneyBehaviors>
<ScriptExecution>Allow</ScriptExecution>
</UserJourneyBehaviors>
...
</RelyingParty>
When referencing external CSS/JS files, the URL must be absolute. This is true for the head section of HTML files as well as any references within JavaScript. Relative URL's can only be referenced within a CSS file.
Incorrect:
<link href="./css/assets.css" rel="stylesheet" type="text/css" />
Correct:
<link href="https://your-storage-account.blob.core.windows.net/your-container/css/assets.css" rel="stylesheet" type="text/css" />

What is the right way to access images in Jhipster

I have some images under src/main/webapp/dist/img
I am able to access these files from my html templates, using relative paths:
<img src="../../../dist/img/user2-160x160.jpg" class="user-image" alt="User Image">
If I move the file to a subfolder, I have to update all paths.
What is the correct way to access images in a JHipster generated application?
Put it into the content folder and you can reference like this:
<img src="/content/avatar.png" />

Kentico Media Library Relative URL

We have a Kentico project where we're using Azure Blob Storage for our media storage. When selecting a media file in a page, it stores the URL like this: www.ourhost.net/blobcontainer/kenticosite/media/medialibrary/picture.jpg
We are also using ImageProcessor.org. This only works when the image is requested through the host itself, so we need the media library selector to store the absolute URL like this: /blobcontainer/kenticosite/media/medialibrary/picture.jpg
How can this be done?
Thanks in advance. Nicolas.
I assume you are talking about Media selection form control, is that correct?
In this case the solution is for you to remove the protocol/domain from the absolute URL which is stored by the form control. You can do this by creating Custom macro since you are using Portal engine macros.
The purpose of the macro will simply be to take the absolute URL and make it a relative URL.
Instead of using this:
<img src="{% CurrentDocument["HeaderImage"] #%}" alt="{% CurrentDocument["Title"] #%}" />
You would call it like:
<img src="{% MyMacros.GetRelativeUrl(CurrentDocument["HeaderImage"]) #%}" alt="{% CurrentDocument["Title"] #%}" />
As you can see I'm using "MyMacros" namespace which is a best practise as it will enable you to keep all your macros organized. You can create custom namespaces as per this article

Resources