mj-font does not work in mjml.
Here is what I am trying to do in index.mjml:
<mjml>
<mj-head>
<mj-font name="testFont" href="testFont.ttf"/>
</mj-head>
<mj-body>
<mj-section>
<mj-column>
<mj-text font-family="testFont" align="center" font-size="20px">
Just a text
</mj-text>
</mj-column>
</mj-section>
</mj-body>
</mjml>
Here is the screenshot of the project directory:
Here is what I see in the app:
And here is what the font should look like:
What am I missing here and how could I make my font work?
Thank you.
I have found it difficult to use custom fonts using the mj-font tag. If you use a google font api it seems to work correctly.
Example using Google font
<mj-font name="Raleway" href="https://fonts.googleapis.com/css?family=Raleway" />
Taking that into consideration, I have started to using the following and has worked for me: (it goes between <mj-style></mj-style> tags)
#font-face {
font-family: testFont;
src: url(https://cdn2.hubspot.net/hubfs/199900/fonts/someFontFile.ttf)
format('truetype');
}
I would normally use a .woff file instead of a .ttf file.
Diving deeper into it, if you go to a Google font link such as https://fonts.googleapis.com/css?family=Raleway in your web browser, the contents of the file is this:
/* latin-ext */
#font-face {
font-family: 'Raleway';
font-style: normal;
font-weight: 400;
src: local('Raleway'), local('Raleway-Regular'), url(https://fonts.gstatic.com/s/raleway/v13/1Ptug8zYS_SKggPNyCMIT4ttDfCmxA.woff2) format('woff2');
unicode-range: U+0100-024F, U+0259, U+1E00-1EFF, U+2020, U+20A0-20AB, U+20AD-20CF, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
/* latin */
#font-face {
font-family: 'Raleway';
font-style: normal;
font-weight: 400;
src: local('Raleway'), local('Raleway-Regular'), url(https://fonts.gstatic.com/s/raleway/v13/1Ptug8zYS_SKggPNyC0IT4ttDfA.woff2) format('woff2');
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
Back to your problem... Since the file that you are loading with the <mj-font> tag is a binary file, I would imagine that mjml doesn't know how to process it. If the file were a .woff font file then it might work. Perhaps they could change this in the near future. After all, it is a very useful tool.
Related
I'm trying to follow some YT tutorial about Bootstrap 5 with the use of some tools like Sass.
Author of this video in his example at the beginning is testing if his script for compiling Sass code is working.
Here's the screenshot of his work:
screenshot 1
I tried to do the same thing and I got an error saying:
Error: Sass variables aren't allowed in plain CSS.
Here's my code:
$primary: #ff0000;
.test-1 {
color: $primary;
}
And the screenshot: screenshot 2
This showed up after compiling my script:
/* Error: Sass variables aren't allowed in plain CSS.
* ,
* 1 | $primary: #ff0000;
* | ^^^^^^^^
* '
* scss/style.css 1:1 root stylesheet */
body::before {
font-family: "Source Code Pro", "SF Mono", Monaco, Inconsolata, "Fira Mono",
"Droid Sans Mono", monospace, monospace;
white-space: pre;
display: block;
padding: 1em;
margin-bottom: 1em;
border-bottom: 2px solid black;
content: "Error: Sass variables aren't allowed in plain CSS.\a \2577 \a 1 \2502 $primary: #ff0000;\a \2502 ^^^^^^^^\a \2575 \a scss/style.css 1:1 root stylesheet";
}
Screenshot of terminal
I think that my code looks the same as his, so where is the problem? Had some rules of Sass had changed since the video was posted?
Here is my info from package.json:
"sass": "^1.45.2"
},
"dependencies": {
"#fortawesome/fontawesome-free": "^5.15.4",
"autoprefixer": "^10.4.1",
"bootstrap": "^5.1.3",
"postcss": "^8.4.5",
"postcss-cli": "^9.1.0"
And his:
"sass": "^1.32.12"
},
"dependencies": {
"#fortawesome/fontawesome-free": "^5.15.3",
"autoprefixer": "^10.2.5",
"bootstrap": "^5.0.0",
"postcss-cli": "^8.3.1"
What is your file extension? It should be .scss. => my-style.scss
TYPO3 11.5.4
I want to add a Plain HTML content element to a page, e.g.:
<style type="text/css">
h1#testheader { font-weight: bold; }
</style>
<h1 id="testheader">
Header
</h1>
(just as a simplified example)
But rendered output is:
<style type="text/css"> h1#testheader { font-weight: bold; } </style>
Header
I thought that style is allowed because I set:
lib.parseFunc.allowTags = ...,style,...
lib.parseFunc_RTE.allowTags = ...,style,...
but it doesn't work.
Setting
lib.parseFunc.htmlSanitize = 0
helps but is there something better to allow <style> in Plain HTML content elements?
EDIT:
Looking into the DB entry the html tags are not encoded, so no "<" or ">" instead of "<" and ">", so it's not an issue of the RTE.
After some more research (hours of hours again invested) I come to the conclusion that the only way is to extend the HTMLSanitizer.
The following sources have been used for this solution:
https://punkt.de/de/blog/2021/htmlsanitizer-in-typo3.html
https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/9.5.x/Important-94484-IntroduceHTMLSanitizer.html
https://gist.github.com/ohader/2239dab247e18d23e677fd1b816f4fd5
The complete solution to allow <style>,<script> and <iframe> is shown below.
Still I am not able to allow <font> with this approach!
It's implemented in a local site package (gpcf_theme) and composer is used.
Add <style>,<script> and <iframe> to
lib.parseFunc.allowTags = ... style, ..., iframe, script, ...
in the TypoScript part of the site package.
style seems to be standard and is already part of this list.
The path to the local site package is:
local_packages/gpcf_theme
with a symbolic link to it from:
public/typo3conf/ext/gpcf_theme -> ../../../local_packages/gpcf_theme
These are the important file changes:
local_packages/gpcf_theme/composer.json:
{
"name": "oheil/gpcf_theme",
...
"autoload": {
"psr-4": {
"Oheil\\GpcfTheme\\": "Classes/"
}
},
...
}
local_packages/gpcf_theme/ext_localconf.php:
<?php
defined('TYPO3_MODE') || die();
...
$GLOBALS['TYPO3_CONF_VARS']['SYS']['htmlSanitizer']['default'] = \Oheil\GpcfTheme\MyDefaultBuilder::class;
...
local_packages/gpcf_theme/Classes/MyDefaultBuilder.php
<?php
namespace Oheil\GpcfTheme;
use TYPO3\CMS\Core\Html\DefaultSanitizerBuilder;
use TYPO3\HtmlSanitizer\Behavior;
use TYPO3\HtmlSanitizer\Behavior\Attr;
use TYPO3\HtmlSanitizer\Behavior\Tag;
class MyDefaultBuilder extends \TYPO3\CMS\Core\Html\DefaultSanitizerBuilder
{
protected function createBehavior(): \TYPO3\HtmlSanitizer\Behavior
{
// https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/9.5.x/Important-94484-IntroduceHTMLSanitizer.html
return parent::createBehavior()
->withName('common')
->withTags(
(new Tag(
'style',
Tag::ALLOW_CHILDREN + Behavior::ENCODE_INVALID_TAG
))->addAttrs(
(new Attr('type')),
...$this->globalAttrs
),
(new Tag(
'iframe',
Tag::ALLOW_CHILDREN
))->addAttrs(
...array_merge(
$this->globalAttrs,
[$this->srcAttr],
$this->createAttrs('scrolling', 'marginwidth', 'marginheight', 'frameborder', 'vspace', 'hspace', 'height', 'width')
)
),
(new Tag(
'script',
Tag::ALLOW_CHILDREN
))->addAttrs(
...array_merge(
$this->globalAttrs,
[$this->srcAttr]
)
),
// more tags...
);
}
}
After these changes of course you need to clear the TYPO3 cache and (not sure here) you need to do:
composer remove "oheil/gpcf_theme"
composer require "oheil/gpcf_theme"
The above is working now, but I am still happy for any expert to give some more insights in what is wrong or can be done better, perhaps easier?
And why does this not work for <font> ?
Example:
<font class="font713099">Some Text</font>
inside the file variables.scss of the ionic3 project it does the import of two fonts: roboto and noto-sans as follows:
#import "roboto";
#import "noto-sans";
Where do these fonts come from? How to import raleway font? I have tried to put this line and it does not work:
#import "raleway";
So I just checked my node_modules and the roboto and noto-sans fonts are stored in node_modules/ionic-angular/fonts/
If you want to use the raleway font, you should be in possession of the .ttf, .woff, and .woff2 files. If you only have the .ttf font, check out FontSquirrel's font files generator
Location: src/assets/fonts/Raleway.ttf etc.
Then you can create your font (app.component.scss or variables.scss)
#font-face {
font-family: 'Raleway';
font-weight: 200;
src: url('../assets/fonts/Raleway.ttf') format('truetype');
src: url('../assets/fonts/Raleway.woff') format('woff');
src: url('../assets/fonts/Raleway.woff2') format('woff2');
}
Now you can use your font:
p { font-family: "Raleway" !important; }
Or change the default font of your ionic app (variables.scss)
$font-family-md-base: "Raleway";
$font-family-ios-base: "Raleway";
$font-family-wp-base: "Raleway";
Answer Credit
I implemented the Klaviyo Popup in the way that is explained at https://help.klaviyo.com/hc/en-us/articles/115005249548-Add-and-Customize-a-Legacy-Popup. How can I configure the error messages when the form does not validate? For example in the documentation I found this:
<script type="text/javascript" src="//www.klaviyo.com/media/js/public/klaviyo_subscribe.js"></script>
<script type="text/javascript">
KlaviyoSubscribe.attachModalSignUp({
list: 'LIST_ID',
delay_seconds: 10.5,
content: {
clazz: ' klaviyo_modal_LIST_ID',
header: 'Join our Newsletter!',
subheader: 'Get the latest and greatest news from us.',
button: 'Subscribe Me!',
success: 'Thanks! Check your email for a confirmation.',
extra_fields: ["$first_name", "$last_name"],
styles: '.klaviyo_modal.klaviyo_modal_LIST_ID { font-family: "Helvetica Neue", Arial}.klaviyo_modal.klaviyo_modal_LIST_ID .klaviyo_header { color:#222;}.klaviyo_modal.klaviyo_modal_LIST_ID .klaviyo_subheader { color:#222;}.klaviyo_modal.klaviyo_modal_LIST_ID .klaviyo_submit_button,.klaviyo_modal.klaviyo_modal_LIST_ID .klaviyo_submit_button span { background-color:#0064cd; background-image: none; border-radius: 2px;}.klaviyo_modal.klaviyo_modal_LIST_ID .klaviyo_submit_button:hover,.klaviyo_modal.klaviyo_modal_LIST_ID .klaviyo_submit_button span:hover { background-color:#0064cd; background-image: none; }.klaviyo_modal.klaviyo_modal_LIST_ID .klaviyo_inner,.klaviyo_modal.klaviyo_modal_LIST_ID .klaviyo_fieldset .klaviyo_field_group input[type=text],.klaviyo_modal.klaviyo_modal_LIST_ID .klaviyo_fieldset .klaviyo_field_group input[type=email] { border-radius: 2px;}'
}
});
</script>
Notice how in the documentation they include this part:
success: 'Thanks! Check your email for a confirmation.',
I was expecting to see something like this for error messages:
error_message: 'My custom error message.',
Is there a way to configure custom error messages? Thank you.
When reading this Klaviyo's blog entry at https://www.klaviyo.com/blog/new-klaviyo-popup-builder, it is my impression that they want to focus on this New Klaviyo Form Builder, which is great for people who need something easier than writing HTML/CSS. It would not surprise me if Klaviyo does not have a way to customize error messages using the "Legacy Popup", as they call it at https://help.klaviyo.com/hc/en-us/articles/115005249548-Add-and-Customize-a-Legacy-Popup, even though to me it should not be a "legacy" way to build pop-ups in Klaviyo.
I'm trying to translate some CSS to ScalaCSS and I can't quite figure out how to encode a pattern of "class subclass". Here is a specific example:
.navbar-top-links {
margin-right: 0;
}
.navbar-top-links li {
display: inline-block;
}
.navbar-top-links li:last-child {
margin-right: 15px;
}
In the quickstart you can see the use of & to define child styles:
".navbar-top-links" - (
marginRight(0),
&("li") - (
display.inlineBlock,
&.lastChild -
marginRight(15 px)
)
)