Related articles using F2C & NoNumber Articles Anywhere

compat f2c pro The essence of this code is that Form2Content 'delivers' an array (list) of Joomla article title and ID's which can be selected in the submission form. This article list is than visualised as Related Articles (in the current article) using NoNumber Articles Anywhere extension.

The goal: To let users select related articles from a list and visualise this list in the article you are creating.

Important: In the examples below we are using the Database Lookup (mult-select) field type with unique name RELATEDARTICLES.

1) Creating the related article list (array) in the submission form

We want our user to be able to select one or more related articles from a list of Joomla articles. For this we use the Database Lookup (mult-select) field type. Please read this article on how to configure the field and create an article selection list.

2) Visualise the related articles in the article

In step 1 we created the 'input', the possibility of selecting one or more Joomla articles. Now we want to visualise (render) the articles in the F2C template in such a way that we can see a 'clickable' list of related articles.

Creating SEF links in Joomla 1.7 can be tricky. As you might know we don't like re-inventing the wheel so we will be using  a great extension (Joomla plugin) called Articles Anywhere from NoNumber.

Articles Anywhere Joomla plugin

The syntax for the Articles Anywhere plugin is very simple: (please note I replaced {} with [] tp prevent rendering.

 [article Some article]...[/article]
[article some-article]...[/article]
[article 123]...[/article]

In between the tags you can add data like article URL, intro text, main text etc.

Example:

[article 123][link][title}[/link][introtext:100][/article]

This will render the title with link of article 123 and the first 100 characters of the article.

F2C template code

The F2C template code, using Smarty for the above example becomes the following. As always replace Joomla plugin { } with {ldelim} {rdelim}:

{ldelim}article 123{rdelim}{ldelim}link{rdelim}{ldelim}title{rdelim}{ldelim}/link{rdelim}{ldelim}introtext:100{rdelim}{ldelim}/article{rdelim}

3) Converting the array into a list using Smarty

Since we are creating a list of unknown number of items from an array we will use the Smarty syntax {foreach} to create the list. In the array the key is stored in the variable $k and the value (item) in $i. The later we don't need since Articles Anywhere can already get it for us.

{foreach from=$RELATEDARTICLES_VALUES key=k item=i name=thislist}{ldelim}article $k{rdelim}{ldelim}link{rdelim}{ldelim}title{rdelim}{ldelim}/link{rdelim}{ldelim}introtext:100{rdelim}{ldelim}/article{rdelim}
{/foreach}

4) Some examples

Comma separated list of article titles with link

{foreach from=$RELATEDARTICLES_VALUES key=k item=i name=thislist}
{ldelim}article {$k}{rdelim}< a href="/ {ldelim}url{rdelim} ">{ldelim}title{rdelim}{ldelim}/article{rdelim}{if $smarty.foreach.thislist.last}.{else}, {/if}
{/foreach}

Note: The name=thislist is required to add the . after the last item

List of article introductions with read more

 

F2C Cheat-sheet

An overview of all template parameters (placeholders for your form data). These are used in your F2C intro and main template to parse the data from your submission forms into the Joomla article.

Download

Footer

Form2Content, a Joomla CCK Documentation © 2010 - 2015 Open Source Design | Powered by Form2Content