Commit a4e4ee85 authored by Sanjay Chauhan's avatar Sanjay Chauhan 💛
Browse files

[FEATURE] Initial version of Extensions

parent a5a5e67b
.. ==================================================
.. FOR YOUR INFORMATION
.. --------------------------------------------------
.. -*- coding: utf-8 -*- with BOM.
.. include:: ../../../Includes.txt
Clearing the cache after editing records
----------------------------------------
News has a built-in mechanism that takes care of clearing the cache after manipulation of News records.
When a list or detail view is rendered on a page, a cache tag in format ``tx_news_pid_PID`` (where PID is the uid of the news storage folder) is added. Each time a news record is edited, deleted or created, this cache entry is flushed. No additional cache configuration is needed if only the News plugins are used.
If you use other ways of displaying news records (e.g. an RSS feed created by TypoScript on a page without a News plugin), the cache is not flushed automatically.
This can be done automatically by using this command in the PageTsConfig: ::
TCEMAIN.clearCacheCmd = 123,456,789
The code needs to be added to the sys folder where the news records are edited. Change the example page ids to the ones which should be cleared, e.g. a page with an RSS feed.
You can use: ::
TCEMAIN.clearCacheCmd = pages
to clear the complete caches as well ::
TCEMAIN.clearCacheCmd = cacheTag:tx_news
to clear all caches of pages on which the news plugins are used but beware of performance issues when news records are edited often.
.. Hint::
The mentioned TCEMAIN settings are part of the TYPO3 core and can be used therefore not only for the news extension.
.. ==================================================
.. FOR YOUR INFORMATION
.. --------------------------------------------------
.. -*- coding: utf-8 -*- with BOM.
.. include:: ../../../Includes.txt
ICalendar
---------
Displaying an iCalendar feed is the same as a normal list view, just with a different template.
Therefore you won't need any different configuration to e.g. excluded categories or configure the single view page.
.. only:: html
.. contents::
:local:
:depth: 3
The template for the iCalendar feed can be found in the file Resources/Private/Templates/News/List.ical.
The "magic" which uses the List.ical template instead of the List.html is the following configuration:
.. code-block:: typoscript
plugin.tx_news.settings.format = ical
plugin.tx_news.settings.domain.data = getEnv:HTTP_HOST
plugin.tx_news.settings.useStdWrap = domain
iCalendar feed by TypoScript
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
A very simple way to generate the iCalendar feed is using plain TypoScript. All you need is to use the given TypoScript and adopt it to your needs.
.. code-block:: typoscript
[globalVar = TSFE:type = 9819]
config {
disableAllHeaderCode = 1
xhtml_cleaning = none
admPanel = 0
metaCharset = utf-8
additionalHeaders = Content-Type:text/calendar;charset=utf-8
disablePrefixComment = 1
}
pageNewsICalendar = PAGE
pageNewsICalendar {
typeNum = 9819
10 < tt_content.list.20.news_pi1
10 {
switchableControllerActions {
News {
1 = list
}
}
settings < plugin.tx_news.settings
settings {
categories = 9
categoryConjunction = notor
limit = 30
detailPid = 25
startingpoint = 24
format = ical
domain.data = getEnv:HTTP_HOST
useStdWrap = domain
}
}
}
[global]
This example will show all news records which don't have the category with the uid 9 assigned and are saved on the page with uid 24.
The iCalendar feed itself can be found with the link **/?type=9819**.
iCalendar feeds by using a normal plugin
""""""""""""""""""""""""""""""""""""""""
Sometimes it is more convenient to generate the iCalendar feed using the normal plugin.
The biggest advantage is that the complete configuration can be done within the backend without touching TypoScript.
To create an ICalendar feed based on a plugin follow this steps:
#. Create a new page.
#. Add the news plugin and define the configuration you need. E.g. startingpoint, page with the single view, ...
#. Define a new TypoScript template and use a code like below. **Very
important** : Use config.absRefPrefix = http://www.yourdomain.tld/ to
produce absolute urls for links and images!
.. code-block:: typoscript
page = PAGE
page.10 < styles.content.get
config {
# deactivate Standard-Header
disableAllHeaderCode = 1
# no xhtml tags
xhtml_cleaning = none
admPanel = 0
metaCharset = utf-8
# define charset
additionalHeaders = Content-Type:text/calendar;charset=utf-8
disablePrefixComment = 1
}
# set the format
plugin.tx_news.settings.format = ical
# set the domain for real unique uids
plugin.tx_news.settings.domain.data = getEnv:HTTP_HOST
plugin.tx_news.settings.useStdWrap = domain
# delete content wrap
tt_content.stdWrap >
**Important:** If your output still contains HTML code, please check your TypoScript
(especially from css\_styled\_content) as this HTML is produced there!
Automatic iCalendar feeds - based on plugins
""""""""""""""""""""""""""""""""""""""""""""
There are use cases where many different list views are needed and each list view should also get its own iCalendar feed **without any additional configuration**.
The TypoScript code looks like this.
.. code-block:: typoscript
[globalVar = TSFE:type = 9819]
lib.stdheader >
tt_content.stdWrap.innerWrap >
tt_content.stdWrap.wrap >
# get away <div class="feEditAdvanced-firstWrapper" ...> if your logged into the backend
styles.content.get.stdWrap >
pageNewsICalendar = PAGE
pageNewsICalendar.typeNum = 9819
pageNewsICalendar.10 < styles.content.get
pageNewsICalendar.10.select.where = colPos=0 AND list_type = "news_pi1"
pageNewsICalendar.10.select {
orderBy = sorting ASC
max = 1
}
config {
# deactivate Standard-Header
disableAllHeaderCode = 1
# no xhtml tags
xhtml_cleaning = none
admPanel = 0
metaCharset = utf-8
# you need an english locale to get correct rfc values for <lastBuildDate>, ...
locale_all = en_EN
# define charset
additionalHeaders = Content-Type:text/calendar;charset=utf-8
disablePrefixComment = 1
}
# set the format
plugin.tx_news.settings.format = ical
# set the domain for real unique uids
plugin.tx_news.settings.domain.data = getEnv:HTTP_HOST
plugin.tx_news.settings.useStdWrap = domain
# delete content wrap
tt_content.stdWrap >
[global]
**Some explanations**
The page object ``pageNewsICalendar`` will render only those content elements which are in colPos 0 and are a news plugin. Therefore all other content elements won't be rendered in the iCalendar feed.
Misc
^^^^
Add a link to the iCalendar feed in the list view
"""""""""""""""""""""""""""""""""""""""""""""""""
To be able to render a link in the header section of the normal page which points to the iCalendar feed you can use something like this in your List.html fluid template.
.. code-block:: xml
<n:headerData>
<link rel="alternate" type="text/calendar" title="iCalendar 2.0" href="<f:uri.page additionalParams="{type:9819}"/>" />
</n:headerData>
Change the iCalendar feed link with RealURL
"""""""""""""""""""""""""""""""""""""""""""
If you want to rewrite the URL, use a configuration like this one.
.. code-block:: php
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['realurl']['_DEFAULT'] = array(
'fileName' => array (
'defaultToHTMLsuffixOnPrev' => 0,
'acceptHTMLsuffix' => 1,
'index' => array(
'calendar.ical' => array(
'keyValues' => array(
'type' => 9819,
)
),
)
)
);
This will change the URL to :code:`/feed.ical`.
.. ==================================================
.. FOR YOUR INFORMATION
.. --------------------------------------------------
.. -*- coding: utf-8 -*- with BOM.
.. include:: ../../Includes.txt
Best practice
-------------
.. only:: html
This chapter describes some best practice concepts
.. toctree::
:maxdepth: 5
:titlesonly:
IntegrationWithTypoScript/Index
ClearCache/Index
Realurl/Index
PredefineFields/Index
Rss/Index
ICalendar/Index
.. ==================================================
.. FOR YOUR INFORMATION
.. --------------------------------------------------
.. -*- coding: utf-8 -*- with BOM.
.. include:: ../../../Includes.txt
Integrations with TypoScript
----------------------------
This page gives you same examples which you can use for integrating EXT:news into a website.
.. only:: html
.. contents::
:local:
:depth: 1
Add news by TypoScript
^^^^^^^^^^^^^^^^^^^^^^
If EXT:news should be integrated by using TypoScript only, you can use this code snippet:
.. code-block:: typoscript
lib.news = USER
lib.news {
userFunc = TYPO3\CMS\Extbase\Core\Bootstrap->run
extensionName = News
pluginName = Pi1
vendorName = GeorgRinger
switchableControllerActions {
News {
1 = list
}
}
settings < plugin.tx_news.settings
settings {
//categories = 49
limit = 30
detailPid = 31
overrideFlexformSettingsIfEmpty := addToList(detailPid)
startingpoint = 13
}
}
Now you can use the object lib.news.
List and detail on the same page using TypoScript
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
This is the example of how to display list and detail view on the same page.
.. code-block:: typoscript
# Basic plugin settings
lib.news = USER
lib.news {
userFunc = TYPO3\CMS\Extbase\Core\Bootstrap->run
pluginName = Pi1
vendorName = GeorgRinger
extensionName = News
controller = News
settings =< plugin.tx_news.settings
persistence =< plugin.tx_news.persistence
view =< plugin.tx_news.view
}
Configure list and detail actions:
.. code-block:: typoscript
lib.news_list < lib.news
lib.news_list {
action = list
switchableControllerActions.News.1 = list
}
lib.news_detail < lib.news
lib.news_detail {
action = detail
switchableControllerActions.News.1 = detail
}
Insert configured objects to wherever you want to use them, depending on the GET parameter of detail view:
.. code-block:: typoscript
[globalVar = GP:tx_news_pi1|news > 0]
page.10.marks.content < lib.news_detail
[else]
page.10.marks.content < lib.news_list
[end]
Add news to breadcrumb menu
^^^^^^^^^^^^^^^^^^^^^^^^^^^
If you want to show the news title in the breadcrumb menu if the single view is currently selected, use a TypoScript like this:
.. code-block:: typoscript
lib.navigation_breadcrumb = COA
lib.navigation_breadcrumb {
stdWrap.wrap = <ul class="breadcrumb">|</ul>
10 = HMENU
10 {
special = rootline
#special.range = 1
1 = TMENU
1 {
noBlur = 1
NO = 1
NO {
wrapItemAndSub = <li>|</li>
ATagTitle.field = subtitle // title
stdWrap.htmlSpecialChars = 1
}
CUR <.NO
CUR {
wrapItemAndSub = <li class="active">|</li>
doNotLinkIt = 1
}
}
}
# Add news title if on single view
20 = RECORDS
20 {
stdWrap.if.isTrue.data = GP:tx_news_pi1|news
dontCheckPid = 1
tables = tx_news_domain_model_news
source.data = GP:tx_news_pi1|news
source.intval = 1
conf.tx_news_domain_model_news = TEXT
conf.tx_news_domain_model_news {
field = title
htmlSpecialChars = 1
}
stdWrap.wrap = <li>|</li>
stdWrap.required = 1
}
}
The relevant part starts with *20 = RECORDS* as this cObject renders the title of the news article. **Important:** Never forget the *source.intval = 1* to avoid SQL injections and the *htmlSpecialChars = 1* to avoid Cross-Site Scripting!
Add HTML to the header part in the detail view.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
There might be a use case where you need to add specific code to the header part when the detail view is rendered.
There are some possible ways to go.
Plain TypoScript
""""""""""""""""
You could use a code like the following one to render e.g. the title of a news article inside a title-tag.
.. code-block:: typoscript
[globalVar = TSFE:id = NEWS-DETAIL-PAGE-ID]
config.noPageTitle = 2
temp.newsTitle = RECORDS
temp.newsTitle {
dontCheckPid = 1
tables = tx_news_domain_model_news
source.data = GP:tx_news_pi1|news
source.intval = 1
conf.tx_news_domain_model_news = TEXT
conf.tx_news_domain_model_news {
field = title
htmlSpecialChars = 1
}
wrap = <title>|</title>
}
page.headerData.1 >
page.headerData.1 < temp.newsTitle
[global]
Usage of a ViewHelper
"""""""""""""""""""""
Use a viewHelper of EXT:news to write any code into the header part. The code could look like this
<n:headerData><script>var newsId = {newsItem.uid};</n:headerData>
If you want to set the title tag, you can use a specific viewHelper:
.. code-block:: html
<n:titleTag>{newsItem.title}</n:titleTag>
Fallback in Detail view if no news found
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
If the detail view is called without a news uid given, an error is thrown (depending on the setting **settings.errorHandling**).
If the desired behaviour is to show a different news record this can be set in the plugin with the field "singleNews".
The drawback would be that the alternative news record would be always the same. If this should be kind of dynamic, take a
look at the given TypoScript snippet:
.. code-block:: typoscript
plugin.tx_news.settings {
overrideFlexformSettingsIfEmpty = singleNews,cropMaxCharacters,dateField,timeRestriction,orderBy,orderDirection,backPid,listPid,startingpoint
useStdWrap = singleNews
singleNews.stdWrap.cObject = CONTENT
singleNews.stdWrap.cObject {
table = tx_news_domain_model_news
select {
max = 1
orderBy = datetime
pidInList = 3
}
renderObj = TEXT
renderObj.field = uid
}
}
By using the field *useStdWrap* it is possible to call the full range of stdWrap on any setting. In this case the first news record
from the page with uid 3 is used as fallback.
.. ==================================================
.. FOR YOUR INFORMATION
.. --------------------------------------------------
.. -*- coding: utf-8 -*- with BOM.
.. include:: ../../../Includes.txt
Predefine fields of records
---------------------------
This section will show you how you can predefine values of fields in records in the TYPO3 backend.
Default values
^^^^^^^^^^^^^^
.. tip:: This is a feature of TYPO3 itself, so you can use this also for all other tables and fields.
If you want to use some default values, you can use this code inside the TsConfig:
.. code-block:: typoscript
# Syntax is always TCAdefaults.<tablename>.<fieldname> = value
TCAdefaults {
tx_news_domain_model_news {
author = John Doe
}
}
Select fields
^^^^^^^^^^^^^
If you want to preselect a value from a select field, you need to set the value of the option field as value.
If you want to remove an option from a select field you can take a look at this example which removes the
option "Images" from the media selection dropdown:
.. code-block:: typoscript
TCEFORM.tx_news_domain_model_media {
type.removeItems = 0
}
Archive date
^^^^^^^^^^^^
EXT:news allows you to use an improved syntax to predefine the archive date by using this PagesTsConfig:
.. code-block:: typoscript
tx_news.predefine.archive = <value>
As value you can use anything which can be interpreted by the php function strtotime (http://de2.php.net/manual/en/function.strtotime.php).