F2C Related article plugins

Create relations between articles in Joomla using Form2Content

Creating a relations between data (Joomla articles) is a complex thing and not natively supported by Joomla. There are tagging components which use keyword ‘relations’ to display related articles and there are some 3rd party extensions which work in similar fashion. In Form2Content it is now possible to create relations between Joomla articles and show data from related articles in an article using the F2C templating engine.

Creating relations between articles other than keyword or Joomla category based is now possible! It's not even very difficult but because Form2Content remains a TOOL and not an out of the box solution, you will have to do some stuff yourself! Please read the documentation very carefully, support is only provided if you show understanding!

F2C Article relations if for Joomla 2.5/3.x and F2C Pro only and requires a more advanced understanding of F2C!

Small bit of history, but important for overall understanding!

Form2Content has developed over the past few years and gradually using the Database Lookup field it has been possible to link (create a relation) between a F2C articles and one or more other Joomla articles. The output of this relation is an array of Joomla title & ID of the selected articles.
Using 3rd party extensions like NuNumber’s Articles Anywhere and the array output we could display the intro or whole Joomla article within another Joomla article by including the Articles Anywhere plugin within our F2C template.
What was not possible was templating the data from the related articles within our article. In other words, you could just show the title, intro or main body text. Not bad but we thought too limited.

REQUIREMENTS: For each relation you need TWO F2C Content Types!

Maybe logical for most but let’s spill it out nevertheless, you need two (2) F2C content types. You also need to understand how to add a single or multi-select Database lookup field with the relevant MySQL query in your submission form.

So what are ‘related articles’, a DEMO CASE STUDY?

The easiest way to explain what we mean with relation articles within Joomla is using the following example. Let’s say you are building a website for a school. You have two types of content, namely CLASSES and STUDENTS.

THE MISSION: We want to show the students with ID in each class article and we want to show the class & teacher name in each student article, for as many classes and students as we like. We also want the information to be updated automatically when we change either student or class data ….

Direction of the relation between content types

There is a ONE to MANY relation …. but which way is the relation build? Student to classes or classes to students?
OPTION 1) In each student profile you have a (single select) database lookup field in which you can choose a class and a text-box for the student ID. You can add as many students as you like or they can do it themselves when registering on the website. Naturally the classes need to be in the ‘system’ first.
This option uses the F2C Related Articles plugin
OPTION 2) In each class profile you have a (multi select) database lookup field in which you can select multiple students and a text-box for the teacher’s name. Teachers can manage their classes and add the students. Naturally the students need to be in the ‘system’ first.

Think before you start!!!

Form2Content is the TOOL, not the ‘out of box solution’. You have to think in which way you collect your data (articles are submitted) and thus which way you want to build your relations.

In this demo case it’s easiest (most logical) to first add the classes and let the students select which class they are in. We will continue with OPTION 1.

The F2C setup for adding students to classes

In this setup you want to have added your student classes first!

  • Form2Content Pro for Joomla 2.5 (license)
  • F2C core SEF plugin (free)
  • F2C Related articles plugin (free)
  • A Joomla category called students
  • A Joomla category called classes
  • A F2C Content Type called classes with at least one text-box field called teachers_name. The class articles are saved in the Joomla category ‘classes’.
  • A F2C Content Type called students with a single-select database lookup field to the Joomla category ‘classes’ and a text-box called student_ID. Saving the Joomla students articles in the default Joomla category ‘students’.

NOTE: Using sub-categories is possible, just makes the MySQL query different. We’re keeping it simple for now.

How the F2C Related Articles Plugin works

Because you never know beforehand how many students have linked to your class you cannot actually display them when you save/create your article. That is why we use a plugin which will look this up when you render the Joomla article. What is does is:

See which articles of content type 2 are RELATED to this article of content type 1 and display information for each of those articles according to a template.

The F2C Related Articles Plugin syntax

As with every Joomla content plugin there is syntax to be added to the Joomla article. Since we generate the article HTML using F2C templates we need to add the plugin syntax in our F2C main or intro template (that’s up to you and is determined where you want to display the related articles).
The plugin syntax is:

{plgContentF2cRelatedArticles}[Joomla Article Id],[F2C Reference Field Id],[Inner template],[Outer template]{/plgContentF2cRelatedArticles}
  • The parameter [Joomla Article Id] must be the Joomla Article Id or the string 'auto'. When set to auto the plug-in will use the Id for the current article.
  • The parameter [F2C Reference Field Id] contains the Id of the F2C Content Type Field which provides the look-up mechanism and is off a different content type.
  • The parameter [Inner Template] contains the name of the Smarty template that will be rendered for every related article.
  • The optional parameter [Outer Template] contains the name of the Smarty template that will contain the repeated output of the Inner Template. The Outer Template must contain the template parameter {$F2C_RELATED_ARTICLES_OUTPUT}, this will be replaced by the repeating output for every related article.
As always we will need to replace the {} with {ldelim} and {rdelim} because of Smarty syntax!

F2C Template code for the student's CLASS ARTICLE

In the class article we want to show the students who selected this class. So we add the plugin code to our Classes Content Type template.

main_template_classes.tpl

{ldelim}plgContentF2cRelatedArticles{rdelim}{$JOOMLA_ID},29,inner_template_students.tpl,outer_template_students.tpl{ldelim}/plgContentF2cRelatedArticles{rdelim}

In this case the single-select dabase lookup field ID is found in the students content type (and is field id 29). This means that this is the F2C field in which the student selects a class and a relationship is born!

Sub-templating the related articles

We have created the relation between the articles, we have added the plugin syntax in the F2C article template. The only thing left is to create the F2C sub-templates for the visualization of, in this case, the student information.

For this we use two sub-templates, an outer (placeholder) and inner template. The inner template will be repeated for every article that’s related to this article. In our example it will be the student data.

The outer template is the placeholder for the inner template and can be used to add non repeating content like headers or starting and closing tags.

The sub-templates need to be placed in the Form2Content template folder

< website >/media/com_form2content/templates

inner_template_students.tpl

The inner template is used to show student data for EACH student …. In other words, it’s repeated per student. Now we wanted to show the student name and the student ID, including a read more link to the actual article!

Remember, we are now using the data from the student content type! This means the Joomla article title is the student name!
<li><a href=”{$JOOMLA_ARTICLE_LINK_SEF}” target=”_self”>{$JOOMLA_TITLE} – {$STUDENTS_ID}</a>
</li>

outer_template_class.tpl

The outer template is a placeholder for the inner template an can be used for start and ending information. In this case we use it to add a subtitle and start our unordered list and close it at the end.

Always include the {$F2C_RELATED_ARTICLES_OUTPUT} in the outer template!
<h2>My class</h2>
<ul>
{$F2C_RELATED_ARTICLES_OUTPUT}
</ul>
Please have a look at the image for a visualisation of what we made.

F2C Template code for the STUDENT ARTICLE

In this case you actually link to the class in the article itself. What is left is getting the content of the class from the other content type. This is a reverse relation to the previous situation so we need a second type of plugin, the F2C Related Articles Reverse Plugin.
What the reverse plugin does is:

See which articles of content type 2 are SELECTED in this article of content type 1 and display information for each of those articles according to a template (set layout).

In our DEMO we only select one other article but it could be multiple articles.

The F2C Related Articles Reverse Plugin syntax

Naturally we kept the syntax very similar to the previous example.

{plgContentF2cRelatedArticlesReverse}[Joomla Article Id],[F2C Reference Field  Id],[Inner template],[Outer template]{/plgContentF2cRelatedArticlesReverse}

As always we will need to replace the {} with {ldelim} and {rdelim} because of Smarty syntax!

main_template_students.tpl

Within the article of the student we want to display the class name and teacher’s name. This was selected in the drop-down but the data needs to be retrieved using the plugin.

{ldelim}plgContentF2cRelatedArticlesReverse{rdelim}{$JOOMLA_ID},29,inner_template_students.tpl,outer_template_students.tpl{ldelim}/plgContentF2cRelatedArticlesReverse{rdelim}

inner_template_class.tpl

The inner template is used to show class information and a link to the class article.

Remember, we are using data from the classes content type! This means the Joomla title is the class name.
<li><a href=”{$JOOMLA_ARTICLE_LINK_SEF}” target=”_self”>{$JOOMLA_TITLE} – {$TEACHER_NAME}</a>
</li>

outer_template_class.tpl

The outer template is a placeholder for the inner template an can be used for start and ending information. In this case we use it to add a subtitle and start our unordered list and close it at the end.

<h2>My class</h2>
<ul>
{$F2C_RELATED_ARTICLES_OUTPUT}
</ul>

That's it ;)

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