You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you want to display articles from another website, you can do so using custom HTML templates.
Demo Screenshot
JSON Feed
To retrieve data from another website, the well-known feeds are RSS or Atom, but the best format for communicating remains JSON, so we decided to develop a script that uses them all: JSON Feed.
So, if you wish to copy/paste the following codes into your customization but with your own feed, it must be formatted in JSON Feed or you must edit the following script to adapt it.
Template
Common
Let's try the following code and copy it into a template file like customization/html/homeTop.html:
<divdata-widget="feed"
data-url="https://www.ecrins-parcnational.fr/flux_actus.json"
data-limit="6"
data-title="Découvrir les dernières actualités"
></div>
data-widget="feed" (mandatory): all HTML tags with this data attribute and the value “feed” will be parsed by the corresponding script.
data-url (mandatory): this is the feed source. If left blank, nothing happens.
data-limit (optional - default Infinity): is the number of elements to be displayed.
data-title (optional): allows to add a title to the section
Internationalization
If the feed is only available in one language, we suggest you paste it only in the suffixed template: homeTop-en.html.
If you have feeds available in different languages, you can duplicate the template with the language code as a suffix as above, or you can use the {{ language }} variable.
Using the HTML example above, let's assume that JSON feeds are available via these urls https://www.ecrins-parcnational.fr/en/flux_actus.json for the English version and https://www.ecrins-parcnational.fr/fr/flux_actus.json for the French version. You can therefore only define homeTop.html with the following content:
<divdata-widget="feed"
data-url="https://www.ecrins-parcnational.fr/{{ language }}/flux_actus.json"
></div>
Widget in details page
It works in the same way.
You can create the file customization/html/details/feedWidget.html and paste the following template:
The main difference with the common template is that you don't have to define the data-title attribute, as the title is automatically defined in translated files under the key details.[file-widget-name].
With our example, we need to add these lines in customization/translations/fr.json :
{
+ "details": {+ "feedWidget": "Actualités"+ }
}
Script:
All this won't work without the associated script. You can copy/paste the script below into customization/html/scriptsHeader.html:
The first action is to add a className to the template in order to hide it if it is empty.
If there is no data-url defined, or if there is an error when retrieving the data, or if the data returns 0 elements, the script stops execution and nothing is displayed.
The source URL must provide a JSON feed format, otherwise it will try to loop inside as if the response were the contents of the items key of the JSON feed. No other checks are made, so if your JSON is not properly formatted, errors may occur.
For the card content, it tries to get the value of summary, if this key has no value, it tries the value of content_text. And if this key also has no value, it finally tries with content_html. Be careful with the last property: you have to trust the source because it executes a innerHTML.
The text was updated successfully, but these errors were encountered:
If you want to display articles from another website, you can do so using custom HTML templates.
Demo Screenshot
JSON Feed
To retrieve data from another website, the well-known feeds are RSS or Atom, but the best format for communicating remains JSON, so we decided to develop a script that uses them all: JSON Feed.
So, if you wish to copy/paste the following codes into your customization but with your own feed, it must be formatted in JSON Feed or you must edit the following script to adapt it.
Template
Common
Let's try the following code and copy it into a template file like
customization/html/homeTop.html
:data-widget="feed"
(mandatory): all HTML tags with this data attribute and the value “feed” will be parsed by the corresponding script.data-url
(mandatory): this is the feed source. If left blank, nothing happens.data-limit
(optional - defaultInfinity
): is the number of elements to be displayed.data-title
(optional): allows to add a title to the sectionInternationalization
If the feed is only available in one language, we suggest you paste it only in the suffixed template:
homeTop-en.html
.If you have feeds available in different languages, you can duplicate the template with the language code as a suffix as above, or you can use the
{{ language }}
variable.Using the HTML example above, let's assume that JSON feeds are available via these urls
https://www.ecrins-parcnational.fr/en/flux_actus.json
for the English version andhttps://www.ecrins-parcnational.fr/fr/flux_actus.json
for the French version. You can therefore only definehomeTop.html
with the following content:Widget in details page
It works in the same way.
You can create the file
customization/html/details/feedWidget.html
and paste the following template:Don't forget to call the
feedWidget
in the desired details page incustomization/config/details.json
.The main difference with the common template is that you don't have to define the
data-title
attribute, as the title is automatically defined in translated files under the keydetails.[file-widget-name]
.With our example, we need to add these lines in
customization/translations/fr.json
:Script:
All this won't work without the associated script. You can copy/paste the script below into
customization/html/scriptsHeader.html
:A few explanations about the script:
className
to the template in order to hide it if it is empty.data-url
defined, or if there is an error when retrieving the data, or if the data returns 0 elements, the script stops execution and nothing is displayed.items
key of the JSON feed. No other checks are made, so if your JSON is not properly formatted, errors may occur.summary
, if this key has no value, it tries the value ofcontent_text
. And if this key also has no value, it finally tries withcontent_html
. Be careful with the last property: you have to trust the source because it executes ainnerHTML
.The text was updated successfully, but these errors were encountered: