Custom tags in TYPO3 content - typo3

new here, and also new to TYPO3.
I need to put something like [imagebox, title='box1'] into content editor and that will be replaced by a text and image with some javascript effect (text and image are managed in the DB elsewhere, the tag is just for the placement in the page).
I've read that TYPO3 has a mechanism for adding custom tags and I managed to make them accepted in the RTE.
I tried instead of [imagebox..... to use
<imagebox>box1</imagebox>
with something like this (copied from web):
tt_content.text.20.parseFunc.tags {
imagebox < lib.parseFunc.tags.link
imagebox = TEXT
imagebox.value= replaced
# imagebox = PHP_SCRIPT
# imagebox {
# stripNL = 0
# Pass a parameter from Typoscript to a PHP script:
# UID of the page containing the SINGLE view of tt_news
# id_singleView = 18
# Call the PHP script
# file = fileadmin/scripts/imagebox_parser.php
# }
}
lib.parseFunc.tags.imagebox < tt_content.text.20.parseFunc.tags.imagebox
should be able to replace content between tags.
I've commented call to php function just tried to get a text replacement for starters.
I've put that in the main root template Setup, but nothing is replaced.
I've also tried other examples from the web with no success.
Did anyone have situation like this?
Are there better approaches for that in TYPO3? (I'm using v7.6.23)
Any suggestion or hint is appreciated.
EDIT: using FSC on textmedia element

I think your examples are outdated. (the object PHP_SCRIPT is obsolete for a long time)
You might have a look at the documentation for your TYPO3 version:
https://docs.typo3.org/typo3cms/TyposcriptReference/7.6/Functions/Parsefunc/
you also need to enhance the parsefunc where you need it. That can depend on:
CSC or FSC?
which kind of content element (CE) do you use? (be sure to enhance the rendering of that CE)

Related

Add a static template to my typo3 extension

I have created an extension with sitepackagebuilder.com and the idea is just to write some static html.
I know that when you have a controller you can call the templates by following the convention names. But what if you don't have a controller? What I need, at least for now, is just to install the extension, add the plugin into a page and get some static content in that page.
I can imagine that this is set in a typoscript file but I'm quite noob with all the typoscript thing.
I'm getting this error:
'No Content Object definition found at TypoScript object path "tt_content.list.20.heboorganigram_organigram"'
Until I define that object in my typoscript file. I have tried this.
tt_content.list.20.heboorganigram_organigram = PAGE
tt_content.list.20.heboorganigram_organigram.10 = TEMPLATE //(or FLUIDTEMPLATE same result)
tt_content.list.20.heboorganigram_organigram.10.template = FILE
tt_content.list.20.heboorganigram_organigram.10.template.file = fileadmin/Organigram.html
And then I don't get an error but I also don't get the content from my Organigram.html, this is just trying stuffs, I actually don't know if this is what I need to do.
Before creating new Content Elements you first have to create the Page Template, for that have a look at the sitepackage tutorial https://docs.typo3.org/m/typo3/tutorial-sitepackage/master/en-us/FluidTemplates/Index.html
If you already got the page template, have a look at https://docs.typo3.org/m/typo3/reference-coreapi/master/en-us/ApiOverview/ContentElements/AddingYourOwnContentElements.html
Provided you already did the steps above, for getting the frontend output you are interested in the step Configure the frontend rendering
So the TypoScript should look something like this:
lib.contentElement {
templateRootPaths.200 = EXT:heboorganigram/Resources/Private/Templates/
}
tt_content {
examples_newcontentelement =< lib.contentElement
examples_newcontentelement {
templateName = NewContentElement
}
}
Then you need to place your Organigram.html file in the Templates Folder in inside the sitepackage.

Can I select the layout to use for a page with Wyam?

I'm working on a theme for Wyam and I'm wondering if there's a way to set the layout that should be used in the markdown file for a particular page. As far as I have seen so far, it seems that each page created with markdown uses _Layout.cshtml
To be more specific. I'm creating an "about.md" page, which has a different layout then then other (default) pages.
So what I would like to do is use metadata to select the layout. For example
Layout: _About.cshtml
or
Layout: _About
Is this possible with Wyam?
In A Razor File
Pages in the Wyam recipes (I'm assuming you're using either the blog or docs recipe) are processed by Razor. The use of a _Layout.cshtml is by convention in the recipe, but alternate layouts can be specified using standard Razor syntax. You can do so by placing the following at the top of the about page .cshtml file (under your front matter):
#{
Layout = "_About.cshtml";
}
In A Markdown File
Markdown files are also processed by the Razor engine, so the technique above would work if it weren't for the Markdown processor escaping the # symbol. There's really no good way around that, and the simple answer to your question is you can't specify an alternate layout for a Markdown file.
However, one of the advantages of using a code-driven generator like Wyam is that you have a lot of control. In this case, you can replace the RenderPages pipeline with one that will do exactly what you want. Add the following to your wyam.config file:
int index = Pipelines.IndexOf(Blog.RenderPages);
Pipelines.Remove(Blog.RenderPages);
Pipelines.Insert(index, Blog.RenderPages,
(IPipeline)new Wyam.Web.Pipelines.RenderPages(
Blog.RenderPages,
new Wyam.Web.Pipelines.RenderPagesSettings
{
Pipelines = new string[] { "Pages" },
Layout = (doc, ctx) => doc.String("Layout", "/_Layout.cshtml")
}));
Then you'll be able to add a "Layout" value as front matter exactly like you wrote in your question.
This was a good idea in general, so I've also opened an issue to add this behavior to the recipe by default.

How to get the Log In Form on every page? (for example in footer) Typo3

Is there a way to get the Log In Form for Frontend User on every page? I would prefer the footer.
And if someone is logged in you can see the Log Out Button.
Is this possible without an extension?
You can copy the default felogin output to wherever you want on your template. For example use lib.login, copy the plugin.tx_felogin_pi1 into it, change the template and you're fine.
lib.login < plugin.tx_felogin_pi1
lib.login.templateFile = path/to/your/template/file
More you can see in the official documentation: https://docs.typo3.org/typo3cms/extensions/felogin/8.7/Configuration/Index.html
In general there are three options to include a CE (e.g. the Login-form) on all pages:
use typoscript to generate the CE. Normally the CEs are defined in tt_content, from where you could copy the base configuration and adapt it. For some plugins you also find a complete configuration beyond lib (for newer extensions there you only find the settings). All the configuration must be done in typoscript.
use typoscript to render the content of a special page/ column. In this variant you have a special page only for content referenced somewhere else. Advantage: you could configure the CE in the usual way. Try to avoid referencing CEs by uid as an editor might disable or delete the current element(s) and insert a new one which would not be rendered.
use a special column in your root page and inherit the content to all subpages. Advantage: you could change the inherited content easily on each page (if this column is available in the current backend layout).
example for 3:
variables {
footer_content < styles.content.get
footer_content.select.where = colPos = 15
footer_content.slide = -1
}

Why can't I access my extensions' settings on the frontend?

Trying to access a few settings that I've created in my constants.txt file. It looks like this:
plugin.tx_my_ext {
settings {
# cat=plugin.tx_my_ext/urgences; type=boolean; label=Activer les urgences
activerUrgences = 0
}
}
Then in my setup.txt file I have this:
plugin.tx_my_ext.settings.activerUrgences = {$plugin.tx_my_ext.settings.activerUrgences}
Any reason why I wouldn't be able to access my settings using {settings} in my Fluid layout?
BTW, my extension name does include an underscore _ between the words. I have tried removing the underscore, then removing the tx_, and then a combination of those two.
Any help would be appreciated!
Thanks
For ext with key my_ext it should be plugin.tx_myext.settings
Make sure that you 'Included static from extension' in your TypoScript Template. If your ext is not available on the list add it in ext_localconf.php like that:
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addStaticFile($_EXTKEY, 'Configuration/TypoScript', 'MyExt');
Do not forget to clear System cache and FE cache at least million times ;)
Use TypoScript object browser to check if on given page your plugins TS is still available (maybe something resets TS in meanwhile:
Finally make sure that you don't clear $this->settings array within your controller, if you do manipulate it for any reason assign it to the view again before view rendering,like that:
$this->view->assign('settings', $this->settings);

CKEditor automatically strips classes from div

I am using CKEditor as a back end editor on my website. It is driving me round the bend though as it seems to want to change the code to how it sees fit whenever I press the source button. For example if I hit source and create a <div>...
<div class="myclass">some content</div>
It then for no apparent reason strips the class from the <div>, so when I hit source again it has been changed to...
<div>some content</div>
I presume this irritating behaviour can be turned off in the config.js, but I have been digging and cant find anything in documentation to turn it off.
Disabling content filtering
The easiest solution is going to the config.js and setting:
config.allowedContent = true;
(Remember to clear browser's cache). Then CKEditor stops filtering the inputted content at all. However, this will totally disable content filtering which is one of the most important CKEditor features.
Configuring content filtering
You can also configure CKEditor's content filter more precisely to allow only these element, classes, styles and attributes which you need. This solution is much better, because CKEditor will still remove a lot of crappy HTML which browsers produce when copying and pasting content, but it will not strip the content you want.
For example, you can extend the default CKEditor's configuration to accept all div classes:
config.extraAllowedContent = 'div(*)';
Or some Bootstrap stuff:
config.extraAllowedContent = 'div(col-md-*,container-fluid,row)';
Or you can allow description lists with optional dir attributes for dt and dd elements:
config.extraAllowedContent = 'dl; dt dd[dir]';
These were just very basic examples. You can write all kind of rules - requiring attributes, classes or styles, matching only special elements, matching all elements. You can also disallow stuff and totally redefine CKEditor's rules.
Read more about:
Content filtering in CKEditor – why do you need content filter.
Advanced Content Filter – in deep description of the filtering mechanism.
Allowed content rules – how to write allowed content rules.
I found a solution.
This turns off the filtering, it's working, but not a good idea...
config.allowedContent = true;
To play with a content string works fine for id, etc, but not for the class and style attributes, because you have () and {} for class and style filtering.
So my bet is for allowing any class in the editor is:
config.extraAllowedContent = '*(*)';
This allows any class and any inline style.
config.extraAllowedContent = '*(*);*{*}';
To allow only class="asdf1" and class="asdf2" for any tag:
config.extraAllowedContent = '*(asdf1,asdf2)';
(so you have to specify the classnames)
To allow only class="asdf" only for p tag:
config.extraAllowedContent = 'p(asdf)';
To allow id attribute for any tag:
config.extraAllowedContent = '*[id]';
etc etc
To allow style tag (<style type="text/css">...</style>):
config.extraAllowedContent = 'style';
To be a bit more complex:
config.extraAllowedContent = 'span;ul;li;table;td;style;*[id];*(*);*{*}';
Hope it's a better solution...
Edit: this answer is for those who use ckeditor module in drupal.
I found a solution which doesn't require modifying ckeditor js file.
this answer is copied from here. all credits should goes to original author.
Go to "Admin >> Configuration >> CKEditor"; under Profiles, choose your profile (e.g. Full).
Edit that profile, and on "Advanced Options >> Custom JavaScript configuration" add config.allowedContent = true;.
Don't forget to flush the cache under "Performance tab."
Since CKEditor v4.1, you can do this in config.js of CKEditor:
CKEDITOR.editorConfig = function( config ) {
config.extraAllowedContent = '*[id](*)'; // remove '[id]', if you don't want IDs for HTML tags
}
You can refer to the official documentation for the detailed syntax of Allowed Content Rules
if you're using ckeditor 4.x you can try
config.allowedContent = true;
if you're using ckeditor 3.x you may be having this issue.
try putting the following line in config.js
config.ignoreEmptyParagraph = false;
This is called ACF(Automatic Content Filter) in ckeditor.It remove all unnessary tag's What we are using in text content.Using this command in your config.js file should be turn off this ACK.
config.allowedContent = true;
Please refer to the official Advanced Content Filter guide and plugin integration tutorial.
You'll find much more than this about this powerful feature. Also see config.extraAllowedContent that seems suitable for your needs.
Following is the complete example for CKEDITOR 4.x :
HTML
<textarea name="post_content" id="post_content" class="form-control"></textarea>
SCRIPT
CKEDITOR.replace('post_content', {
allowedContent:true,
});
The above code will allow all tags in the editor.
For more Detail : CK EDITOR Allowed Content Rules
If you use Drupal AND the module called "WYSIWYG" with the CKEditor library, then the following workaround could be a solution. For me it works like a charm. I use CKEditor 4.4.5 and WYSIWYG 2.2 in Drupal 7.33. I found this workaround here: https://www.drupal.org/node/1956778.
Here it is:
I create a custom module and put the following code in the ".module" file:
<?php
/**
* Implements hook_wysiwyg_editor_settings_alter().
*/
function MYMODULE_wysiwyg_editor_settings_alter(&$settings, $context) {
if ($context['profile']->editor == 'ckeditor') {
$settings['allowedContent'] = TRUE;
}
}
?>
I hope this help other Drupal users.
I found that switching to use full html instead of filtered html (below the editor in the Text Format dropdown box) is what fixed this problem for me. Otherwise the style would disappear.
I would like to add this config.allowedContent = true; needs to be added to the ckeditor.config.js file not the config.js, config.js did nothing for me but adding it to the top area of ckeditor.config.js kept my div classes
Another option if using drupal is simply to add the css style that you want to use. that way it does not strip out the style or class name.
so in my case under the css tab in drupal 7 simply add something like
facebook=span.icon-facebook2
also check that font-styles button is enabled
I face same problem on chrome with ckeditor 4.7.1. Just disable pasteFilter on ckeditor instanceReady.This property disable all filter options of Advance Content Filter(ACF).
CKEDITOR.on('instanceReady', function (ev) {
ev.editor.pasteFilter.disabled = true;
});