.. _templatesSnippets:
=================
Assorted snippets
=================
This section contains snippets making EXT:news more awesome which might be useful for your projects as well.
.. contents::
:local:
:depth: 1
Show FAL properties in fluid
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Every property of a file, e.g. the copyright (available via EXT:filemetadata) can be rendered in templates by using e.g. `{file.originalResource.properties.copyright}`.
A full example can look like this
.. code-block:: html
{mediaElement.originalResource.properties.copyright}
Use `{mediaElement.originalResource.properties}` to get all available properties
Improved back links
^^^^^^^^^^^^^^^^^^^
The back link on a detail page is a fixed link to a given page. However it might be that you use multiple list views
and want to change the link depending on the given list view.
A nice solution would be to use this JavaScript jQuery snippet:
.. code-block:: javascript
if ($(".news-backlink-wrap a").length > 0) {
if(document.referrer.indexOf(window.location.hostname) != -1) {
$(".news-backlink-wrap a").attr("href","javascript:history.back();");
}
}
Creating links with Fluid
^^^^^^^^^^^^^^^^^^^^^^^^^
Besides the ViewHelper :html:`` you can also use the ViewHelpers of Fluid itself:
.. code-block:: html
{newsItem.title}
{newsItem.title}
Creating links in PHP
^^^^^^^^^^^^^^^^^^^^^
If you want to create links within PHP you can usw the following snippet as inspiration:
.. code-block:: php
public function createLink(int $pageId, array $arguments = [], bool $absolute = false): string
{
$site = GeneralUtility::makeInstance(SiteFinder::class)->getSiteByPageId($pageUid);
return (string)$site->getRouter()->generateUri(
(string)$pageUid,
$arguments,
'',
($absolute ? RouterInterface::ABSOLUTE_URL : RouterInterface::ABSOLUTE_PATH)
);
}
$pageId = 123; // news detail page uid
$newsRecordUid = 1234; // news record uid
$absolute = true; // full url or relative url
$arguments = [
'tx_news_pi1' => [
'action' => 'detail',
'controller' => 'News',
'news' => $newsRecordId,
],
];
$newsDetailPageUrlForNews = createLink($pageId, $arguments, true);
Set n:link target page in Fluid
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
If the detail page should not be set in the plugin or by a category, it can also be set within the template:
.. code-block:: html
The setting `settings.somePid` can e.g. set with `plugin.tx_news.settings.somePid=123`.
Render category rootline
^^^^^^^^^^^^^^^^^^^^^^^^
If you want to show not only the title of a single category which is related to the news item but the complete category rootline use this snippets.
.. code-block:: html
and
.. code-block:: html
{category.title}
Use current content element in the template
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
If you ever need information from the content element itself, you can use :html:`{contentObjectData.header}`.
Use current page in the template
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
If you ever need information from the current page, you can use :html:`{pageData.uid}`.
Sort tags
^^^^^^^^^
If you want to sort the tags of a news item, you can use a custom ViewHelper or :file:`EXT:vhs`:
.. code-block:: html
Render news items in columns
----------------------------
If you need to list news next to each other and need some additional CSS
classes, you can the following snippet.
The provided example will wrap 3 items into a div with the class "row".
.. code-block:: html
Override pagination labels
--------------------------
To override the labels used in the pagination, you can use the following TypoScript snippet:
.. code-block:: typoscript
plugin.tx_fluid {
_LOCAL_LANG {
// default for default = english language
default {
widget.pagination.next = my custom next
}
de {
widget.pagination.next = nächste Seite
}
}
}
As an alternative it is also possible to adopt the partial `List/Pagination.html` and use XLF files of your own extension.
.. code-block:: html
{f:translate(key:'widget.pagination.next', extensionName: 'yourSitePackage')}