How to add CSS to a TYPO9.5 Extension? - typo3

What is the correct way of adding CSS to the public folder of an extension? What do I need to do in order for that CSS to be loaded in.
For example I have the following structure:
Public/Css/style.css
Configuration/TypoScript/setup.typoscript
Configuration/TypoScript/constants.typoscript
Would I have to add some code in setup.typoscript?

Since TYPO3 8.7 you can add HTML to the header or footer from your Fluid template using the HeaderAssets and FooterAssets sections. For example:
<f:section name="HeaderAssets">
<link rel="stylesheet" href="{f:uri.resource(path: 'Css/styles.css')}"/>
</f:section>
The advantage of this over page.includeCSS is that it is only included whenever that template is rendered, instead of on all pages.

Your CSS has to be in:
extensionkey/Resources/Public/Css/
And then in your typoscript (setup) you can add:
page.includeCSS.csskey = EXT:extensionkey/Resources/Public/Css/style.css
The "csskey" has to be unique identifier.

Related

How to use t3:// TypoLinks in TYPO3 HTML Content Elements without disabling `parseFunc.htmlSanitize` globally?

Since the release of the security patches in August 2021 that prevents Cross-Site Scripting via Rich-Text Content I noticed that the output of HTML Content Elements suddenly changed in our projects. Some tag attributes and tags got removed by the newly introduced HTML Sanitizer (when the template is modified so that t3:// style TypoLinks get rendered).
So simply overriding the default Html.html Fluid Template, changing the <f:format.raw> to <f:format.html> and adding a html decoding like in the following example is no longer sufficient.
<f:section name="Main">
<f:comment> We use this to render links and other stuff in html elements </f:comment>
<f:format.htmlentitiesDecode>
<f:format.html parseFuncTSPath="lib.parseFunc">
{data.bodytext}
</f:format.html>
</f:format.htmlentitiesDecode>
</f:section>
The easiest way to prevent changes in your html codes output provided by HTML Content Elements is to disable the sanitizer globally by adding lib.parseFunc.htmlSanitize = 0 to your TypoScript config, what is not ideal.
How can I disable the parseFunc.htmlSanitize only for this purpose?
Or is there an other solution to render TypoLinks within HTML Content Elements?
Note: You don't need to disable the HTML Sanitizer if you do not override the Html.html template!
Simply make a copy of lib.parseFunc and disable the sanitizer in this copy.
lib.parseHtmlFunc < lib.parseFunc
lib.parseHtmlFunc.htmlSanitize = 0
Then use this lib in your Html.html template.
<f:section name="Main">
<f:comment> We use this to render links and other stuff in html elements </f:comment>
<f:format.htmlentitiesDecode>
<f:format.html parseFuncTSPath="lib.parseHtmlFunc">
{data.bodytext}
</f:format.html>
</f:format.htmlentitiesDecode>
</f:section>
Thanks to #OliverHader for bringing me to the right track.

TYPO3 Image From Extension

I'm a typo newbie, and was wondering, how I can make the following code work in my HTML Template file:
<img src="EXT:extension-name/Resources/Public/Images/Logo/logo-white.png" alt="logo.png">
Looking forward to your anwers, thanks.
This cannot be done in an HTML file but within a Fluid template file you should use the uri.resource viewhelper:
<img src="{f:uri.resource(path: 'Images/Logo/logo-white.png')}" alt="Actual explanation of the logo content">
If used within an Extbase plugin there is nothing else to do.
For templates using the FLUIDTEMPLATE content object you'll need to set the extension name, for example with an extensionName: 'MyExt' as argument:
<img src="{f:uri.resource(path: 'Images/Logo/logo-white.png', extensionName: 'MyExt')}" alt="Actual explanation of the logo content">
Alternatively use controllerExtensionName in your TypoScript setup.

Add custom class to body tag | TYPO3

I want to add custom class to body tag to each page what I want, for example: for Tag pages class <body class="tagClass">, for main page class <body class="mainClass"> and for detailed pages <body class="classDetailed">.
I`m using TYPO3 7.6.0 andi have installed on it Blog extention, this blog extention pages i want this classes.
some examples or link would be very helpful for me.
By the way this post i saw TYPO3 Adding a class to the body tag on a specifc page but it isn`t what i want
Given you are using 'page' as TypoScript ContentObject PAGE and have two different page trees, which starts with page id 10 and 20, you can use following TypoScript setup/configuration:
[PIDinRootline=10]
page.bodyTagAdd = class="foo"
[end]
[PIDinRootline=20]
page.bodyTagAdd = class="bar"
[end]

Open login for inside modal dialog for Joomla 2.5

So I have a specific page that spawns a modal dialog to login/register. I am using Colorbox, and this is working nicely for me. What I need to do is open ONLY the form and not the entire page with header links and such. I understand this can be fixed by adding '?tmpl=component' or '&tmpl=component' to the end of the url. My problem is that my form is stripped of all styling and is terribly ugly. Is there any way I can go about adding styling back to this form? Thanks in advance.
Yes you can get all styles,
This is happen due to using with tmpl=component Normally Joomla using this layout for printing purpose(Print layout) it have only basic styling compared to your default template index.php.
So you need to get your proper styling for the forms you have to add those style sheet to the component.php inside your template folder.
templates/your_template/component.php
Add your basic template style sheet at the top of the file using same like index.php.
eg:
<link rel="stylesheet" href="<?php echo $this->baseurl ?>/templates/system/css/system.css" type="text/css" />
<link rel="stylesheet" href="<?php echo $this->baseurl ?>/templates/beez_20/css/template.css" type="text/css" />
Then tmpl=component view have proper styles applied.
Hope it helps..
I downloaded the entire FTP and did a search for where the basic stylesheets were being included (general.css and system.css) so that I could add my others for style. This can be found/edited in public_html/templates/system/component.php

Limit JavaScript and CSS files on ASP.NET MVC 2 Master Page based on Model and View content

I want to include certain .js and .css files only on pages that need them.
For example, my EditorTemplate DateTime.ascx needs files anytimec.js and anytimec.css.
That template is applied whenever I use either the EditorFor or EditorForModel helper methods in a view for a model with a DateTime type value.
My technique:
I've put this condition into the <head> section of my master page. It checks for a DateTime type property in the ModelMetadata.
<% if (this.ViewData.ModelMetadata.Properties.Any(p => p.ModelType == typeof(DateTime))) { %>
<link href="../../Content/anytimec.css" rel="stylesheet" type="text/css" />
<script src="../../Scripts/anytimec.js" type="text/javascript"></script>
<% } %>
This has two problems:
Fails if I have nested child models of type DateTime
Unnecessarily triggered by views without EditorFor or EditorForModel methods (example: DisplayForModel)
How can I improve this technique?
Personally, I would use a partial view and an ASP Content Placeholder.
In the Views/Shared have a partial view EditorScripts.ascx which contains the tags defining the scripts to be included in your editing pages.
Then put a placeholder in the Site.Master <head> tag, something like this:
<asp:ContentPlaceHolder ID="HeadContent" runat="server" />
The, in any view that you want/need the scripts, put this code:
<asp:Content ContentPlaceHolderID="HeadContent" runat="server">
<% Html.RenderPartial("EditorScripts"); %>
</asp:Content>
This isn't a perfect solution and isn't as dynamic as you would like. The reason for using a partial view is that if you decide to update or add more scripts to those views, then you only have to update it in one location.
Another way would be to have a Editor.Master page that contains these scripts and other editor specific things then have that master use the Site.Master as it's master page. Then all editor views would have the Editor.Master as their master page.
HTH
I think the telerik web asset manager allows you to accomplish what you want and is open source.